Code

Ticket #19585: 19585-1.diff

File 19585-1.diff, 1.3 KB (added by claudep, 16 months ago)
Line 
1diff --git a/django/http/cookie.py b/django/http/cookie.py
2index 78adb09..50ff549 100644
3--- a/django/http/cookie.py
4+++ b/django/http/cookie.py
5@@ -1,6 +1,7 @@
6 from __future__ import absolute_import, unicode_literals
7 
8 from django.utils.encoding import force_str
9+from django.utils import six
10 from django.utils.six.moves import http_cookies
11 
12 
13@@ -48,7 +49,9 @@ else:
14         if not _cookie_allows_colon_in_names:
15             def load(self, rawdata):
16                 self.bad_cookies = set()
17-                super(SimpleCookie, self).load(force_str(rawdata))
18+                if not six.PY3 and isinstance(rawdata, six.text_type):
19+                    rawdata = force_str(rawdata)
20+                super(SimpleCookie, self).load(rawdata)
21                 for key in self.bad_cookies:
22                     del self[key]
23 
24diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
25index 67172d9..c76d8ea 100644
26--- a/tests/regressiontests/httpwrappers/tests.py
27+++ b/tests/regressiontests/httpwrappers/tests.py
28@@ -588,3 +588,7 @@ class CookieTests(unittest.TestCase):
29         c['name']['httponly'] = True
30         self.assertTrue(c['name']['httponly'])
31 
32+    def test_load_dict(self):
33+        c = SimpleCookie()
34+        c.load({'name': 'val'})
35+        self.assertEqual(c['name'].value, 'val')