mirror of https://github.com/django/django.git
Fixed #18403 -- Initialized bad_cookies in SimpleCookie
Thanks Stefano Crosta for the report.
This commit is contained in:
parent
7008ed61c5
commit
f2a4452882
|
@ -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())
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue