summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/http/cookie.py2
-rw-r--r--tests/httpwrappers/tests.py9
2 files changed, 11 insertions, 0 deletions
diff --git a/django/http/cookie.py b/django/http/cookie.py
index 40cf58def8..eef0c35759 100644
--- a/django/http/cookie.py
+++ b/django/http/cookie.py
@@ -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())
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index 17bb98e24d..287d800c21 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -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)