Skip to content
Browse files

Fixed #18403 -- Initialized bad_cookies in SimpleCookie

Thanks Stefano Crosta for the report.
  • Loading branch information...
1 parent 7008ed6 commit f2a44528825ac07ca28c8bb7dc01b4375df8dc2c @e0ne e0ne committed with timgraham
Showing with 11 additions and 0 deletions.
  1. +2 −0 django/http/cookie.py
  2. +9 −0 tests/httpwrappers/tests.py
View
2 django/http/cookie.py
@@ -64,6 +64,8 @@ def _BaseCookie__set(self, key, real_value, coded_value):
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
9 tests/httpwrappers/tests.py
@@ -618,3 +618,12 @@ def test_load_dict(self):
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)

0 comments on commit f2a4452

Please sign in to comment.
Something went wrong with that request. Please try again.