diff --git a/django/http/__init__.py b/django/http/__init__.py index 5df734cceb3..5439aa6c63c 100644 --- a/django/http/__init__.py +++ b/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 @@ class QueryDict(MultiValueDict): 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 diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index f32ef14ae93..aaaef1d8b04 100644 --- a/tests/regressiontests/requests/tests.py +++ b/tests/regressiontests/requests/tests.py @@ -31,4 +31,8 @@ GET:{}, POST:{}, COOKIES:{}, META:{}> + +>>> from django.http import parse_cookie +>>> parse_cookie('invalid:key=true') +{} """