11

Even have seen a page, where in the same url were both of enocoded and not encoded commas, like: https://example.com/product?filter_color:blue,green&filter_size:xl%2Cxxl

My knowledge about the subject is a bit messy:

  • On the one side, in a URI RFC i've read, comma would be a socalled reserved character and should be in URLs always encoded.
  • On the other side i've seen many websites, where comma wasn't encoded.

The question arose because of usage of both encoded and non encoded variant: how should it be done correctly: encode or non encode?

6
  • 1
  • 1
  • If you do use them, you probably need to be prepared to support the URL with them both encoded and not encoded. Sep 4, 2017 at 14:04
  • @StephenOstermiller: my question is rather about why and how in the same url are both encoded AND non-encoded commas? Why browser doesn't handle them on the same unified art? OR both encoded, EITHER both non-encoded. BTW: in terms of SEO, if both notations are allowed, they should cause duplicated content. So it isn't fully correct to argue, the subject hasn't any SEO impact.
    – Evgeniy
    Sep 4, 2017 at 14:14
  • 1
    An encoded URL is equivalent to its unencoded version (also, eg, punycode domains), there's no duplicate content aspect. It'll only ever be crawled & indexed in one way. Personally, I'd keep funky characters (like space, comma, colon, etc) out of the URL, keep things easy for your users. Sep 6, 2017 at 9:19

1 Answer 1

17

, is a reserved character. Reserved characters are never equivalent (for normalization purposes) to their percent-encoded variants. So these URIs are not equivalent:

http://example.com/?foo,bar
http://example.com/?foo%2Cbar

Neither the URI standard¹ nor the HTTP/HTTPS URI scheme specs define a special role for , in the query component. This means that authors may use , to represent data in the query component (i.e., for whatever they want).

It can make sense to use , together with %2C in an URI’s query component. For example, an author could decide to use , for separating name-value pairs, and %2C for representing commas within values:

http://example.com/?score:1%2C4,time:55

(It doesn’t seem to make sense in the example URI in your question, though. Assuming that the values are "blue" and "green", as well as "xl" and "xxl", it would make more sense to either use , or %2C in both cases. Your example URI would make sense if e.g. the latter case is actually one value, so "xl,xxl".)


¹ Note that RFC 2396 is obsolete. IETF’s URI standard should always be accessible under STD 66, which is currently RFC 3986.

I gave a similar answer to the question Possible side effect using comma in querystring? on Stack Overflow.

1
  • its a real life example - sad but true. for the rest - absolutely agreed. it was my thought too, that different usage of encoded and non encoded commas should be at least explained by different usage purposes, like using as different entities, separator and part of the meaningful value. was just misguided by standard, so i supposed the only one usage kind: or encoded, either non encoded
    – Evgeniy
    Sep 5, 2017 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.