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

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Commit 9fc998d

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
@@ -408,6 +408,8 @@ def OutputString(self, attrs=None):
408 408 append("%s=%s" % (self._reserved[key], _getdate(value)))
409 409 elif key == "max-age" and isinstance(value, int):
410 410 append("%s=%d" % (self._reserved[key], value))
411 +elif key == "comment" and isinstance(value, str):
412 +append("%s=%s" % (self._reserved[key], _quote(value)))
411 413 elif key in self._flags:
412 414 if value:
413 415 append(str(self._reserved[key]))

Lines changed: 10 additions & 0 deletions

Original file line number Diff line number Diff line change
@@ -207,6 +207,16 @@ def test_illegal_chars(self):
207 207 with self.assertRaises(cookies.CookieError):
208 208 C.load(rawdata)
209 209
210 +def test_comment_quoting(self):
211 +c = cookies.SimpleCookie()
212 +c['foo'] = '\N{COPYRIGHT SIGN}'
213 +self.assertEqual(str(c['foo']), 'Set-Cookie: foo="\\251"')
214 +c['foo']['comment'] = 'comment \N{COPYRIGHT SIGN}'
215 +self.assertEqual(
216 +str(c['foo']),
217 +'Set-Cookie: foo="\\251"; Comment="comment \\251"'
218 + )
219 +
210 220
211 221 class MorselTests(unittest.TestCase):
212 222 """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`.