Ticket #6764: safe_cookie.diff

File safe_cookie.diff, 1.1 KB (added by Michael Axiak, 17 years ago)

Patch to squelch cookie parsing errors.

  • django/http/__init__.py

     
    11import os
    2 from Cookie import SimpleCookie
     2from Cookie import SimpleCookie, CookieError
    33from pprint import pformat
    44from urllib import urlencode
    55from urlparse import urljoin
     
    239239def parse_cookie(cookie):
    240240    if cookie == '':
    241241        return {}
    242     c = SimpleCookie()
    243     c.load(cookie)
     242    try:
     243        c = SimpleCookie()
     244        c.load(cookie)
     245    except CookieError:
     246        # Invalid cookie
     247        return {}
     248
    244249    cookiedict = {}
    245250    for key in c.keys():
    246251        cookiedict[key] = c.get(key).value
  • tests/regressiontests/requests/tests.py

     
    3131POST:{},
    3232COOKIES:{},
    3333META:{}>
     34
     35>>> from django.http import parse_cookie
     36>>> parse_cookie('invalid:key=true')
     37{}
    3438"""
Back to Top