Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #6764 -- Added some error checking around cookie decoding. Thanks,

Michael Axiak.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7257 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 30bdabb2b0d01e1f89af18028ab1605db734bd4b 1 parent 8defa8f
@malcolmt malcolmt authored
View
11 django/http/__init__.py
@@ -1,5 +1,5 @@
import os
-from Cookie import SimpleCookie
+from Cookie import SimpleCookie, CookieError
from pprint import pformat
from urllib import urlencode
from urlparse import urljoin
@@ -239,8 +239,13 @@ def urlencode(self):
def parse_cookie(cookie):
if cookie == '':
return {}
- c = SimpleCookie()
- c.load(cookie)
+ try:
+ c = SimpleCookie()
+ c.load(cookie)
+ except CookieError:
+ # Invalid cookie
+ return {}
+
cookiedict = {}
for key in c.keys():
cookiedict[key] = c.get(key).value
View
4 tests/regressiontests/requests/tests.py
@@ -31,4 +31,8 @@
POST:{},
COOKIES:{},
META:{}>
+
+>>> from django.http import parse_cookie
+>>> parse_cookie('invalid:key=true')
+{}
"""
Please sign in to comment.
Something went wrong with that request. Please try again.