encodeURIComponent vs. escape

encodeURIComponent vs. escape

am 07.09.2007 14:50:01 von DannyVucinec

Hi,

I've a problem reading querystring parameters that are 'uri encoded'. Anyone
has a solution for this?

To reproduce the problem, create a classic ASP containing the following code:

-----------------------

Value sent via querystring: <%=
Server.HTMLEncode(Request.QueryString("value")) %>





-----------------------

Now, enter the value "Dré" and submit. The page will show the value "Dré",
but I except Request.QueryString("value") to return the original value, i.e.
"Dré".

Re: encodeURIComponent vs. escape

am 07.09.2007 16:11:58 von Anthony Jones

"Danny Vucinec" wrote in message
news:B8BC5240-3C2A-4D03-9519-35A5FD1F8072@microsoft.com...
> Hi,
>
> I've a problem reading querystring parameters that are 'uri encoded'.
Anyone
> has a solution for this?
>
> To reproduce the problem, create a classic ASP containing the following
code:
>
> -----------------------
>
>

Value sent via querystring: <%=
> Server.HTMLEncode(Request.QueryString("value")) %>


>
>
>
> -----------------------
>
> Now, enter the value "Dré" and submit. The page will show the value
"Dré",
> but I except Request.QueryString("value") to return the original value,
i.e.
> "Dré".

encodeURIComponent correctly encodes using UTF-8 character codes.

Unfortunately IE would incorrectly allow the query portion of a URL to be
sent using whatever local encoding is being used. IIS 5 and 6
correspondingly expect the query portion to be encoded to match the sessions
codepage.

Hence using encodeURIComponent to encode a string into the query generates a
correctly encoded URL which IIS mis-reads.

Use Response.Codepage = 65001 to allow ASP to correctly read the URL.

However unless you reset Response.Codepage to it's original value before
sending any output you will need to ensure you set Response.CharSet =
"UTF-8" and save the page as UTF-8. You will also need to ensure any pages
receiving form posts from the page also have Codepage set to 65001 before
attempting to read the form values.


--
Anthony Jones - MVP ASP/ASP.NET

Re: encodeURIComponent vs. escape

am 13.09.2007 11:38:00 von DannyVucinec

This is somewhat complicated in my web application. I found the following
solution for pages using encode/decodeURIComponent:

function decodeURIComponent(text)
{
return unescape(text);
}

function encodeURIComponent(text)
{
return escape(text).replace(/\+/, "%2B");
}


"Anthony Jones" wrote:

> "Danny Vucinec" wrote in message
> news:B8BC5240-3C2A-4D03-9519-35A5FD1F8072@microsoft.com...
> > Hi,
> >
> > I've a problem reading querystring parameters that are 'uri encoded'.
> Anyone
> > has a solution for this?
> >
> > To reproduce the problem, create a classic ASP containing the following
> code:
> >
> > -----------------------
> >
> >

Value sent via querystring: <%=
> > Server.HTMLEncode(Request.QueryString("value")) %>


> >
> >
> >
> > -----------------------
> >
> > Now, enter the value "Dré" and submit. The page will show the value
> "Dré",
> > but I except Request.QueryString("value") to return the original value,
> i.e.
> > "Dré".
>
> encodeURIComponent correctly encodes using UTF-8 character codes.
>
> Unfortunately IE would incorrectly allow the query portion of a URL to be
> sent using whatever local encoding is being used. IIS 5 and 6
> correspondingly expect the query portion to be encoded to match the sessions
> codepage.
>
> Hence using encodeURIComponent to encode a string into the query generates a
> correctly encoded URL which IIS mis-reads.
>
> Use Response.Codepage = 65001 to allow ASP to correctly read the URL.
>
> However unless you reset Response.Codepage to it's original value before
> sending any output you will need to ensure you set Response.CharSet =
> "UTF-8" and save the page as UTF-8. You will also need to ensure any pages
> receiving form posts from the page also have Codepage set to 65001 before
> attempting to read the form values.
>
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>
>