Description
Symfony version(s) affected: All
Description
When creating a non-raw Cookie, it is impossible to provide a name that contains characters matching the regex class [=,; \t\r\n\013\014]
even though __toString
later performs a urlencode to sanitise this field for output.
How to reproduce
$cookie = new Cookie('yes=please');
Possible Solution
I would expect for it to be permissible to supply any value for the name in the same way that you can for the value in non-raw mode by performing the character validation only in raw mode:
if ($raw && preg_match("/[=,; \t\r\n\013\014]/", $name)) {
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
}
Additional context
It is possible to work around this issue by creating a Cookie in raw mode, but this places additional burden on the implementing application to take care of encoding both the name and value at all times. In my particular use case I am also making use of the Illuminate Cookie Jar forget method which does not expose the ability to operate in raw mode.