mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
Fixed bug with our SimpleCookie regarding load/custom Morsel, and simplified implementation
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16526 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
319b0cfb83
commit
6d029359e9
@ -54,18 +54,10 @@ else:
|
||||
if "httponly" in self:
|
||||
output += "; httponly"
|
||||
return output
|
||||
else:
|
||||
Morsel = Cookie.Morsel
|
||||
|
||||
class SimpleCookie(Cookie.SimpleCookie):
|
||||
if not _morsel_supports_httponly:
|
||||
def __set(self, key, real_value, coded_value):
|
||||
M = self.get(key, Morsel())
|
||||
M.set(key, real_value, coded_value)
|
||||
dict.__setitem__(self, key, M)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
rval, cval = self.value_encode(value)
|
||||
self.__set(key, rval, cval)
|
||||
|
||||
if not _cookie_encodes_correctly:
|
||||
def value_encode(self, val):
|
||||
# Some browsers do not support quoted-string from RFC 2109,
|
||||
@ -91,19 +83,20 @@ else:
|
||||
|
||||
return val, encoded
|
||||
|
||||
if not _cookie_allows_colon_in_names:
|
||||
if not _cookie_allows_colon_in_names or not _morsel_supports_httponly:
|
||||
def load(self, rawdata):
|
||||
self.bad_cookies = set()
|
||||
super(SimpleCookie, self).load(rawdata)
|
||||
for key in self.bad_cookies:
|
||||
del self[key]
|
||||
|
||||
_strict_set = Cookie.BaseCookie._BaseCookie__set
|
||||
|
||||
# override private __set() method:
|
||||
# (needed for using our Morsel, and for laxness with CookieError
|
||||
def _BaseCookie__set(self, key, real_value, coded_value):
|
||||
try:
|
||||
self._strict_set(key, real_value, coded_value)
|
||||
M = self.get(key, Morsel())
|
||||
M.set(key, real_value, coded_value)
|
||||
dict.__setitem__(self, key, M)
|
||||
except Cookie.CookieError:
|
||||
self.bad_cookies.add(key)
|
||||
dict.__setitem__(self, key, Cookie.Morsel())
|
||||
|
@ -291,3 +291,13 @@ class CookieTests(unittest.TestCase):
|
||||
Test that a repeated non-standard name doesn't affect all cookies. Ticket #15852
|
||||
"""
|
||||
self.assertTrue('good_cookie' in parse_cookie('a,=b; a,=c; good_cookie=yes').keys())
|
||||
|
||||
def test_httponly_after_load(self):
|
||||
"""
|
||||
Test that we can use httponly attribute on cookies that we load
|
||||
"""
|
||||
c = SimpleCookie()
|
||||
c.load("name=val")
|
||||
c['name']['httponly'] = True
|
||||
self.assertTrue(c['name']['httponly'])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user