Fixed #18403 -- Initialized bad_cookies in SimpleCookie

Thanks Stefano Crosta for the report.
This commit is contained in:
e0ne 2013-09-09 12:40:37 +03:00 committed by Tim Graham
parent 7008ed61c5
commit f2a4452882
2 changed files with 11 additions and 0 deletions

View File

@ -64,6 +64,8 @@ else:
M.set(key, real_value, coded_value)
dict.__setitem__(self, key, M)
except http_cookies.CookieError:
if not hasattr(self, 'bad_cookies'):
self.bad_cookies = set()
self.bad_cookies.add(key)
dict.__setitem__(self, key, http_cookies.Morsel())

View File

@ -618,3 +618,12 @@ class CookieTests(unittest.TestCase):
c = SimpleCookie()
c.load({'name': 'val'})
self.assertEqual(c['name'].value, 'val')
@unittest.skipUnless(six.PY2, "PY3 throws an exception on invalid cookie keys.")
def test_bad_cookie(self):
"""
Regression test for #18403
"""
r = HttpResponse()
r.set_cookie("a:.b/", 1)
self.assertEqual(len(r.cookies.bad_cookies), 1)