From f08e739bc2ba5d3530a806378087227728369464 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 11 Jan 2013 21:09:33 +0100 Subject: [PATCH] Fixed #19585 -- Fixed loading cookie value as a dict This regression was introduced by the 'unicode_literals' patch. --- django/http/cookie.py | 5 ++++- tests/regressiontests/httpwrappers/tests.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/http/cookie.py b/django/http/cookie.py index 78adb09ce81..50ff549caf3 100644 --- a/django/http/cookie.py +++ b/django/http/cookie.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, unicode_literals from django.utils.encoding import force_str +from django.utils import six from django.utils.six.moves import http_cookies @@ -48,7 +49,9 @@ else: if not _cookie_allows_colon_in_names: def load(self, rawdata): self.bad_cookies = set() - super(SimpleCookie, self).load(force_str(rawdata)) + if not six.PY3 and isinstance(rawdata, six.text_type): + rawdata = force_str(rawdata) + super(SimpleCookie, self).load(rawdata) for key in self.bad_cookies: del self[key] diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index 67172d963cc..c76d8eafe3a 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -588,3 +588,7 @@ class CookieTests(unittest.TestCase): c['name']['httponly'] = True self.assertTrue(c['name']['httponly']) + def test_load_dict(self): + c = SimpleCookie() + c.load({'name': 'val'}) + self.assertEqual(c['name'].value, 'val')