Kaydet (Commit) 8a6f4b4b authored tarafından Miss Islington (bot)'s avatar Miss Islington (bot) Kaydeden (comit) Berker Peksag

bpo-991266: Fix quoting of Comment attribute of SimpleCookie (GH-6555)

(cherry picked from commit d5a2377c)
Co-authored-by: 's avatarBerker Peksag <berker.peksag@gmail.com>
üst 26c289dd
...@@ -436,6 +436,8 @@ class Morsel(dict): ...@@ -436,6 +436,8 @@ class Morsel(dict):
append("%s=%s" % (self._reserved[key], _getdate(value))) append("%s=%s" % (self._reserved[key], _getdate(value)))
elif key == "max-age" and isinstance(value, int): elif key == "max-age" and isinstance(value, int):
append("%s=%d" % (self._reserved[key], value)) 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: elif key in self._flags:
if value: if value:
append(str(self._reserved[key])) append(str(self._reserved[key]))
......
...@@ -216,6 +216,16 @@ class CookieTests(unittest.TestCase): ...@@ -216,6 +216,16 @@ class CookieTests(unittest.TestCase):
with self.assertRaises(cookies.CookieError): with self.assertRaises(cookies.CookieError):
C.load(rawdata) 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): class MorselTests(unittest.TestCase):
"""Tests for the Morsel object.""" """Tests for the Morsel object."""
......
Fix quoting of the ``Comment`` attribute of :class:`http.cookies.SimpleCookie`.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment