Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug with our SimpleCookie regarding load/custom Morsel, and sim…

…plified implementation

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16526 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6d029359e955a6a5fd7e4024ddd9159004c30d20 1 parent 319b0cf
@spookylukey spookylukey authored
View
21 django/http/__init__.py
@@ -54,18 +54,10 @@ def OutputString(self, attrs=None):
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 @@ def value_encode(self, val):
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())
View
10 tests/regressiontests/httpwrappers/tests.py
@@ -291,3 +291,13 @@ def test_repeated_nonstandard_keys(self):
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'])
+
Please sign in to comment.
Something went wrong with that request. Please try again.