[Python-checkins] bpo-991266: Fix quoting of Comment attribute of SimpleCookie (GH-6555)
Berker Peksag
webhook-mailer at python.org
Sun Apr 22 20:58:54 EDT 2018
https://github.com/python/cpython/commit/8a6f4b4bba950fb8eead1b176c58202d773f2f70
commit: 8a6f4b4bba950fb8eead1b176c58202d773f2f70
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Berker Peksag <berker.peksag at gmail.com>
date: 2018-04-23T03:58:51+03:00
summary:
bpo-991266: Fix quoting of Comment attribute of SimpleCookie (GH-6555)
(cherry picked from commit d5a2377c3d70e4143bcbee4a765b3434e21f683a)
Co-authored-by: Berker Peksag <berker.peksag at gmail.com>
files:
A Misc/NEWS.d/next/Library/2018-04-21-00-24-08.bpo-991266.h93TP_.rst
M Lib/http/cookies.py
M Lib/test/test_http_cookies.py
diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py
index be3b080aa3d7..008857b7aaa1 100644
--- a/Lib/http/cookies.py
+++ b/Lib/http/cookies.py
@@ -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]))
diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py
index 2432e0bf5340..234b9ee05762 100644
--- a/Lib/test/test_http_cookies.py
+++ b/Lib/test/test_http_cookies.py
@@ -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."""
diff --git a/Misc/NEWS.d/next/Library/2018-04-21-00-24-08.bpo-991266.h93TP_.rst b/Misc/NEWS.d/next/Library/2018-04-21-00-24-08.bpo-991266.h93TP_.rst
new file mode 100644
index 000000000000..3af6c27cf21d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-04-21-00-24-08.bpo-991266.h93TP_.rst
@@ -0,0 +1 @@
+Fix quoting of the ``Comment`` attribute of :class:`http.cookies.SimpleCookie`.
More information about the Python-checkins
mailing list