bpo-991266: Fix quoting of Comment attribute of SimpleCookie (GH-6555) · python/cpython@d5a2377 (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit d5a2377
File tree
3 files changed
lines changed
3 files changed
lines changed
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])) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -220,6 +220,16 @@ def test_illegal_chars(self): | ||
220 | 220 | with self.assertRaises(cookies.CookieError): |
221 | 221 | C.load(rawdata) |
222 | 222 | |
223 | +def test_comment_quoting(self): | |
224 | +c = cookies.SimpleCookie() | |
225 | +c['foo'] = '\N{COPYRIGHT SIGN}' | |
226 | +self.assertEqual(str(c['foo']), 'Set-Cookie: foo="\\251"') | |
227 | +c['foo']['comment'] = 'comment \N{COPYRIGHT SIGN}' | |
228 | +self.assertEqual( | |
229 | +str(c['foo']), | |
230 | +'Set-Cookie: foo="\\251"; Comment="comment \\251"' | |
231 | + ) | |
232 | + | |
223 | 233 | |
224 | 234 | class MorselTests(unittest.TestCase): |
225 | 235 | """Tests for the Morsel object.""" |
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`. |