diff --git a/django/http/__init__.py b/django/http/__init__.py
a
|
b
|
|
27 | 27 | _morsel_supports_httponly = Cookie.Morsel._reserved.has_key('httponly') |
28 | 28 | # Some versions of Python 2.7 and later won't need this encoding bug fix: |
29 | 29 | _cookie_encodes_correctly = Cookie.SimpleCookie().value_encode(';') == (';', '"\\073"') |
| 30 | # See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256 |
| 31 | _tc = Cookie.SimpleCookie() |
| 32 | _tc.load('f:oo') |
| 33 | _cookie_allows_colon_in_names = 'Set-Cookie: f:oo=' in _tc.output() |
30 | 34 | |
31 | | if _morsel_supports_httponly and _cookie_encodes_correctly: |
| 35 | if _morsel_supports_httponly and _cookie_encodes_correctly and _cookie_allows_colon_in_names: |
32 | 36 | SimpleCookie = Cookie.SimpleCookie |
33 | 37 | else: |
34 | 38 | if not _morsel_supports_httponly: |
… |
… |
|
85 | 89 | |
86 | 90 | return val, encoded |
87 | 91 | |
| 92 | if not _cookie_allows_colon_in_names: |
| 93 | def load(self, rawdata, ignore_parse_errors=False): |
| 94 | if ignore_parse_errors: |
| 95 | self.bad_cookies = [] |
| 96 | self._BaseCookie__set = self._loose_set |
| 97 | super(SimpleCookie, self).load(rawdata) |
| 98 | if ignore_parse_errors: |
| 99 | self._BaseCookie__set = self._strict_set |
| 100 | for key in self.bad_cookies: |
| 101 | del self[key] |
| 102 | |
| 103 | _strict_set = Cookie.BaseCookie._BaseCookie__set |
| 104 | |
| 105 | def _loose_set(self, key, real_value, coded_value): |
| 106 | try: |
| 107 | self._strict_set(key, real_value, coded_value) |
| 108 | except Cookie.CookieError: |
| 109 | self.bad_cookies.append(key) |
| 110 | dict.__setitem__(self, key, None) |
| 111 | |
| 112 | |
88 | 113 | class CompatCookie(SimpleCookie): |
89 | 114 | def __init__(self, *args, **kwargs): |
90 | 115 | super(CompatCookie, self).__init__(*args, **kwargs) |
… |
… |
|
433 | 458 | if not isinstance(cookie, Cookie.BaseCookie): |
434 | 459 | try: |
435 | 460 | c = SimpleCookie() |
436 | | c.load(cookie) |
| 461 | c.load(cookie, ignore_parse_errors=True) |
437 | 462 | except Cookie.CookieError: |
438 | 463 | # Invalid cookie |
439 | 464 | return {} |
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
a
|
b
|
|
1 | 1 | import copy |
2 | 2 | import pickle |
3 | 3 | |
4 | | from django.http import QueryDict, HttpResponse, SimpleCookie, BadHeaderError |
| 4 | from django.http import (QueryDict, HttpResponse, SimpleCookie, BadHeaderError, |
| 5 | parse_cookie) |
5 | 6 | from django.utils import unittest |
6 | 7 | |
7 | 8 | class QueryDictTests(unittest.TestCase): |
… |
… |
|
274 | 275 | c2 = SimpleCookie() |
275 | 276 | c2.load(c.output()) |
276 | 277 | self.assertEqual(c['test'].value, c2['test'].value) |
| 278 | |
| 279 | def test_nonstandard_keys(self): |
| 280 | """ |
| 281 | Test that a single non-standard cookie name doesn't affect all cookies. |
| 282 | """ |
| 283 | self.assertTrue('good_cookie' in parse_cookie('good_cookie=yes;bad:cookie=yes').keys()) |