2

I have a piece of code that redirects to a page using server.urlEncode (fields) when the captcha isn't entered correctly. Code looks like:

sRedirectTo = "page.asp" _ & "?action=vcerr" _ & "&at=" & server.urlEncode(sAdType) _ & "&fn=" & server.urlEncode(sFirstname) _ & "&mn=" & server.urlEncode(sMiddleName) _ & "&ln=" & server.urlEncode(sLastName) _ & "&sx=" & server.urlEncode(sSex) _ & "&pr=" & server.urlEncode(sProvince) _ & "&cn=" & server.urlEncode(sCountry) _ & "&cy=" & server.urlEncode(sCity) _ & "&md=" & server.urlEncode(dMomentDate) _ & "&ag=" & server.urlEncode(iAgree) _ & "&chn=" & server.urlEncode(sCharityName) _ & "&chu=" & server.urlEncode(sCharityUrl) _ & "&city=" & server.urlEncode(sCityID) _ & "&key=" & server.urlEncode(sKeywords) 

However, when the cy entry is for a city like Saint-Jérome, it fails encode the accent. Url in browser bar looks like this: page.asp?action=vcerr[...]&cy=SAINT-JÉRÔME&od=10%2F05%2[...]

Then the text is pulled using QueryString("cy) and displayed on the page, causing the characters to not be displayed correctly.

Is there something I'm missing here? I'm unsure of why server.urlEncode doesn't work.

EDIT:

I checked the variable sRedirectTo while debugging, it seems that the urlEncode does work on the characters, so the switch happens between the Response.redirect and the QueryString. Is it possible that the redirect removed the encoding for the special characters? Also what's strange is that the urlencoding done on the other variables stays intact.

1 Answer 1

1

Make sure you've set your CodePage and Charset to UTF-8 and saved both files in UTF-8.

Testing scripts I used:

r.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Response.Charset = "UTF-8" cy = "SAINT-JÉRÔME" Response.Redirect("p.asp?cy=" & cy) %> 

p.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Response.Charset = "UTF-8" cy = Request.QueryString("cy") Response.Write cy %> 

Output:

SAINT-JÉRÔME 
Sign up to request clarification or add additional context in comments.

2 Comments

What would happen if instead of containing "SAINT-JÉRÔME" the cy variable was assigned "Hello&oops=World"?
@AnthonyWJones: Since my example script doesn't use Server.URLEncode, the output would be "Hello".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.