472,989 Members | 2,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

encodeURIComponent vs. escape

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:

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

<p>Value sent via querystring: <%=
Server.HTMLEncode(Request.QueryString("value")) %></p>
<input id="input" />
<button id="submit" onclick="window.location.assign('Test.asp?value=' +
encodeURIComponent(input.value));">submit</button>

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

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é".
Sep 7 '07 #1
2 12468
"Danny Vucinec" <Da**********@discussions.microsoft.comwrote in message
news:B8**********************************@microsof t.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:
>
-----------------------

<p>Value sent via querystring: <%=
Server.HTMLEncode(Request.QueryString("value")) %></p>
<input id="input" />
<button id="submit" onclick="window.location.assign('Test.asp?value=' +
encodeURIComponent(input.value));">submit</button>

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

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
Sep 7 '07 #2
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" <Da**********@discussions.microsoft.comwrote in message
news:B8**********************************@microsof t.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:

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

<p>Value sent via querystring: <%=
Server.HTMLEncode(Request.QueryString("value")) %></p>
<input id="input" />
<button id="submit" onclick="window.location.assign('Test.asp?value=' +
encodeURIComponent(input.value));">submit</button>

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

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
Sep 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Leif B. Kristensen | last post by:
I'm working with a Python program to insert / update textual data into a PostgreSQL database. The text has single and double quotes in it, and I wonder: What is the easiest way to escape quotes in...
5
by: fochie | last post by:
Greetings, I'm trying to send data to my server using xmlhttp POST. The data being sent is actually an HTML page that is built with javascript in the browser. The HTML code contains a small...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
9
by: Serguei.Goumeniouk | last post by:
Dear Experts, I have a very simple javascript codes with a following lines inside: ............................ var str = ""; .. . . . . . . . . . str = String(new Date()); // #1 str +=...
10
by: Peter Michaux | last post by:
Hi, All Ajax libraries I've read use encodeURIComponent() on the name- value pairs extracted from forms before POST ing the result to the server with and xmlhttprequest. I can understand why...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.