Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the comma URL encoded?

When debugging in ASP.NET MVC, I don't see a difference between:

http://mysite.com?q=hi,bye 

and

http://mysite.com?q=hi%2Cbye 

The querystring param "q" always has a value of "hi,bye".

So why is the comma encoded?

I want to do something like this https://stackoverflow.com/a/752109/173957.

I have this form:

<form method="GET" action="/Search">      <input type="hidden" name="q" value="hi,bye"/>      <input type="submit" value="ok"/> </form> 

How can I prevent this value from being encoded?

like image 688
Scott Coates Avatar asked Jan 12 '12 00:01

Scott Coates


People also ask

Why does URL get encoded?

Why do we need to encode? URLs can only have certain characters from the standard 128 character ASCII set. Reserved characters that do not belong to this set must be encoded. This means that we need to encode these characters when passing into a URL.

What does comma mean in URL?

Users aren't familiar with commas in URLs because they aren't normally used as part of the hierarchy in a link. They can, however, be used to delineate subcomponents within a URL structure. Commas are considered to be "reserved" characters for HTML, which include dollar signs, ampersands, pluses, semicolons, etc.

What does %3D mean in URL?

is a reserved separator character that cannot appear unencoded in the name and value fields, it must be url-encoded as %3D : custom_field_id%5B%5D%3D10=custom_field_value_10%3DFull-time. It is the receiver's responsibility to url-decode the submitted data before then processing it.


2 Answers

The URI spec, RFC 3986, specifies that URI path components not contain unencoded reserved characters and comma is one of the reserved characters. For sub-delims such as the comma, leaving it unencoded risks the character being treated as separator syntax in the URI scheme. Percent-encoding it guarantees the character will be passed through as data.

like image 65
Kyle Jones Avatar answered Oct 13 '22 15:10

Kyle Jones


I found this list of characters that do not require URL encoding: http://web.archive.org/web/20131212154213/http://urldecoderonline.com/url-allowed-characters.htm

Update
Since the original link broke, I used archive.org to get the following text from the page from on December 2013

List of allowed URL characters

Unreserved - May be encoded but it is not necessary

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _ . ~ 

Reserved - Have to be encoded sometimes

! * ' ( ) ; : @ & = + $ , / ? % # [ ] 
like image 20
Alex Avatar answered Oct 13 '22 14:10

Alex