Skip to content

Commit

Permalink
Fixed #6764 -- Added some error checking around cookie decoding. Thanks,
Browse files Browse the repository at this point in the history
Michael Axiak.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7257 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Mar 17, 2008
1 parent 8defa8f commit 30bdabb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions 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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/regressiontests/requests/tests.py
Expand Up @@ -31,4 +31,8 @@
POST:{},
COOKIES:{},
META:{}>
>>> from django.http import parse_cookie
>>> parse_cookie('invalid:key=true')
{}
"""

0 comments on commit 30bdabb

Please sign in to comment.