Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/http/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ def OutputString(self, attrs=None):
append("%s=%s" % (self._reserved[key], _getdate(value)))
elif key == "max-age" and isinstance(value, int):
append("%s=%d" % (self._reserved[key], value))
elif key == "comment" and isinstance(value, str):
append("%s=%s" % (self._reserved[key], _quote(value)))
elif key in self._flags:
if value:
append(str(self._reserved[key]))
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_http_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def test_illegal_chars(self):
with self.assertRaises(cookies.CookieError):
C.load(rawdata)

def test_comment_quoting(self):
c = cookies.SimpleCookie()
c['foo'] = '\N{COPYRIGHT SIGN}'
self.assertEqual(str(c['foo']), 'Set-Cookie: foo="\\251"')
c['foo']['comment'] = 'comment \N{COPYRIGHT SIGN}'
self.assertEqual(
str(c['foo']),
'Set-Cookie: foo="\\251"; Comment="comment \\251"'
)


class MorselTests(unittest.TestCase):
"""Tests for the Morsel object."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix quoting of the ``Comment`` attribute of :class:`http.cookies.SimpleCookie`.