diff options
| author | Collin Anderson <cmawebsite@gmail.com> | 2016-03-11 21:36:08 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-03-15 12:24:06 -0400 |
| commit | 93a135d111c2569d88d65a3f4ad9e6d9ad291452 (patch) | |
| tree | b85448d68a4888d8372c15328fa5f4e30c5ffda2 /django/http | |
| parent | e7e5d9b338cabaafc61b7a0c55ff395b533d8c9e (diff) | |
Fixed #26158 -- Rewrote http.parse_cookie() to better match browsers.
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/cookie.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/django/http/cookie.py b/django/http/cookie.py index 344e59661f..1f10eff95a 100644 --- a/django/http/cookie.py +++ b/django/http/cookie.py @@ -57,18 +57,21 @@ else: def parse_cookie(cookie): - if cookie == '': - return {} - if not isinstance(cookie, http_cookies.BaseCookie): - try: - c = SimpleCookie() - c.load(cookie) - except http_cookies.CookieError: - # Invalid cookie - return {} - else: - c = cookie + """ + Return a dictionary parsed from a `Cookie:` header string. + """ cookiedict = {} - for key in c.keys(): - cookiedict[key] = c.get(key).value + if six.PY2: + cookie = force_str(cookie) + for chunk in cookie.split(str(';')): + if str('=') in chunk: + key, val = chunk.split(str('='), 1) + else: + # Assume an empty name per + # https://bugzilla.mozilla.org/show_bug.cgi?id=169091 + key, val = str(''), chunk + key, val = key.strip(), val.strip() + if key or val: + # unquote using Python's algorithm. + cookiedict[key] = http_cookies._unquote(val) return cookiedict |
