Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special Characters in URL query string

I have a situation where the user is able to enter any characters they want in a URL query string.

Example:

http://localhost/default.aspx?ID=XXXX

http://localhost/default.aspx?ID=&XXXX

http://localhost/default.aspx?ID=#XXXX

The web page must accept the ID parameter as it is no matter what the characters are. However certain special characters such as ampersand(&) and pound(#) creates problems. How can I accept them as is?

like image 871
m0g Avatar asked Jul 19 '11 15:07

m0g


People also ask

How can I include special characters in query strings?

In JavaScript you can use the encodeURI() function. ASP has the Server. URLEncode() function. You can use HttpServerUtility.

How do you represent special characters in a URL?

Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

What characters are allowed in query string?

The query component is a string of information to be interpreted by the resource. Within a query component, the characters ";", "/", "?", ":", "@", "&", "=", "+", ",", and "$" are reserved.


1 Answers

This:

encodeURIComponent(uri)

Where uri is the component after the ?ID=

like image 90
wanovak Avatar answered Oct 07 '22 12:10

wanovak