In some web server, cookie with a comma in value will be split into two cookie (one with empty value). For example, "foo=bar,goo"
will be treated just like "foo=bar;goo="
. Is this right according to RFC?
I find this RFC document but don't know exactly what it means.
cookie-pair = cookie-name "=" cookie-value
cookie-name = token
cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
; US-ASCII characters excluding CTLs,
; whitespace DQUOTE, comma, semicolon,
; and backslash
RFC 6265
A cookie definition begins with a name-value pair. A <cookie-name> can contain any US-ASCII characters except for: the control character, space, or a tab.
Semicolon is not allowed in cookies.
Show activity on this post. When you set a cookie value with one of the following values as mentioned in Cookie#setValue() , With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons.
when browsers output a cookie with an empty name, they omit the equals sign. So Set-Cookie: =bar begets Cookie: bar . commas and spaces in names and values do actually seem to work, though spaces around the equals sign are trimmed. control characters ( \x00 to \x1F plus \x7F ) aren't allowed.
cookie-pair = cookie-name "=" cookie-value
cookie-name = token
cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
; US-ASCII characters excluding CTLs,
; whitespace DQUOTE, comma, semicolon,
; and backslash
What are those keywords: cookie-pair, cookie-name, cookie-value, cookie-octet?
cookie-value
is the right-side part of =
.
cookie-octet
is the real value, enclosed in double quotes or nothing. See:
key="value"
or
key=value
When you put in a ,
(or ;
) see what happens:
key="value,",key2="value2"
or
key=value,,key2=value2
So, your assumption is not quite correct and you must not use comma or semicolon inside the value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With