bpo-991266: Fix quoting of Comment attribute of SimpleCookie (GH-6555) · python/cpython@8a6f4b4 (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Commit 8a6f4b4

miss-islingtonberkerpeksag

and

committed

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

(cherry picked from commit d5a2377) Co-authored-by: Berker Peksag berker.peksag@gmail.com

File tree

3 files changed

lines changed

3 files changed

lines changed

Lines changed: 2 additions & 0 deletions

Original file line number Diff line number Diff line change
@@ -436,6 +436,8 @@ def OutputString(self, attrs=None):
436 436 append("%s=%s" % (self._reserved[key], _getdate(value)))
437 437 elif key == "max-age" and isinstance(value, int):
438 438 append("%s=%d" % (self._reserved[key], value))
439 +elif key == "comment" and isinstance(value, str):
440 +append("%s=%s" % (self._reserved[key], _quote(value)))
439 441 elif key in self._flags:
440 442 if value:
441 443 append(str(self._reserved[key]))

Lines changed: 10 additions & 0 deletions

Original file line number Diff line number Diff line change
@@ -216,6 +216,16 @@ def test_illegal_chars(self):
216 216 with self.assertRaises(cookies.CookieError):
217 217 C.load(rawdata)
218 218
219 +def test_comment_quoting(self):
220 +c = cookies.SimpleCookie()
221 +c['foo'] = '\N{COPYRIGHT SIGN}'
222 +self.assertEqual(str(c['foo']), 'Set-Cookie: foo="\\251"')
223 +c['foo']['comment'] = 'comment \N{COPYRIGHT SIGN}'
224 +self.assertEqual(
225 +str(c['foo']),
226 +'Set-Cookie: foo="\\251"; Comment="comment \\251"'
227 + )
228 +
219 229
220 230 class MorselTests(unittest.TestCase):
221 231 """Tests for the Morsel object."""

Lines changed: 1 addition & 0 deletions

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 +Fix quoting of the ``Comment`` attribute of :class:`http.cookies.SimpleCookie`.