[issue991266] Cookie.py does not correctly quote Morsels

Berker Peksag report at bugs.python.org
Thu Apr 19 23:04:19 EDT 2018


Berker Peksag <berker.peksag at gmail.com> added the comment:

>>> from http.cookies import SimpleCookie
>>> c = SimpleCookie()
>>> c['name'] = 'value'
>>> c['name']['comment'] = '\n'
>>> c['name']['expires'] = '123; path=.example.invalid'
'Set-Cookie: name=value; Comment="\\012"; expires=123; path=.example.invalid'

What do you think that the snippet above should return?

    'Set-Cookie: name=value; Comment="\\012"; expires=Fri, 20 Apr 2018 02:03:13 GMT; path=.example.invalid'

or

    'Set-Cookie: name=value; Comment="\\012"; expires=Fri, 20 Apr 2018 02:03:13 GMT; path=".example.invalid"'

or

    'Set-Cookie: name=value; Comment="\\012"; expires=123; path=".example.invalid"'

?

I don't think the path attribute (or all of them) needs to be quoted unconditionally. Looking at https://tools.ietf.org/html/rfc6265#section-4.1.1, it looks like quoting for cookie-value is optional.

Is there a use case or examples from other programming languages you can share with us?

----------
versions: +Python 3.7, Python 3.8 -Python 3.4, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue991266>
_______________________________________


More information about the Python-bugs-list mailing list