Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15852 -- Modified cookie parsing so it can handle duplicate in…

…valid cookie names. Thanks goes to Fredrik Stålnacke for the report and to vung for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16452 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c159374a33caee14d9903de58a9f4fe879e5741c 1 parent 25c5251
Ramiro Morales ramiro authored
6 django/http/__init__.py
View
@@ -91,7 +91,7 @@ def value_encode(self, val):
if not _cookie_allows_colon_in_names:
def load(self, rawdata, ignore_parse_errors=False):
if ignore_parse_errors:
- self.bad_cookies = []
+ self.bad_cookies = set()
self._BaseCookie__set = self._loose_set
super(SimpleCookie, self).load(rawdata)
if ignore_parse_errors:
@@ -105,8 +105,8 @@ def _loose_set(self, key, real_value, coded_value):
try:
self._strict_set(key, real_value, coded_value)
except Cookie.CookieError:
- self.bad_cookies.append(key)
- dict.__setitem__(self, key, None)
+ self.bad_cookies.add(key)
+ dict.__setitem__(self, key, Cookie.Morsel())
class CompatCookie(SimpleCookie):
6 tests/regressiontests/httpwrappers/tests.py
View
@@ -285,3 +285,9 @@ def test_nonstandard_keys(self):
Test that a single non-standard cookie name doesn't affect all cookies. Ticket #13007.
"""
self.assertTrue('good_cookie' in parse_cookie('good_cookie=yes;bad:cookie=yes').keys())
+
+ def test_repeated_nonstandard_keys(self):
+ """
+ Test that a repeated non-standard name doesn't affect all cookies. Ticket #15852
+ """
+ self.assertTrue('good_cookie' in parse_cookie('a,=b; a,=c; good_cookie=yes').keys())
Please sign in to comment.
Something went wrong with that request. Please try again.