[1.3.X] Backported the fix for #15852 -- Modified cookie parsing so it can handle duplicate invalid 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/branches/releases/1.3.X@17168 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
bf5fdf1397
commit
68f37a9081
|
@ -92,7 +92,7 @@ else:
|
||||||
if not _cookie_allows_colon_in_names:
|
if not _cookie_allows_colon_in_names:
|
||||||
def load(self, rawdata, ignore_parse_errors=False):
|
def load(self, rawdata, ignore_parse_errors=False):
|
||||||
if ignore_parse_errors:
|
if ignore_parse_errors:
|
||||||
self.bad_cookies = []
|
self.bad_cookies = set()
|
||||||
self._BaseCookie__set = self._loose_set
|
self._BaseCookie__set = self._loose_set
|
||||||
super(SimpleCookie, self).load(rawdata)
|
super(SimpleCookie, self).load(rawdata)
|
||||||
if ignore_parse_errors:
|
if ignore_parse_errors:
|
||||||
|
@ -106,8 +106,8 @@ else:
|
||||||
try:
|
try:
|
||||||
self._strict_set(key, real_value, coded_value)
|
self._strict_set(key, real_value, coded_value)
|
||||||
except Cookie.CookieError:
|
except Cookie.CookieError:
|
||||||
self.bad_cookies.append(key)
|
self.bad_cookies.add(key)
|
||||||
dict.__setitem__(self, key, None)
|
dict.__setitem__(self, key, Cookie.Morsel())
|
||||||
|
|
||||||
|
|
||||||
class CompatCookie(SimpleCookie):
|
class CompatCookie(SimpleCookie):
|
||||||
|
|
|
@ -281,3 +281,9 @@ class CookieTests(unittest.TestCase):
|
||||||
Test that a single non-standard cookie name doesn't affect all cookies. Ticket #13007.
|
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())
|
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())
|
||||||
|
|
Loading…
Reference in New Issue