Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13572: copies of QueryDicts now have their encoding set correc…

…tly.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13314 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3180f932369e3a6a1604c5ea98ee7063eeeaf1dd 1 parent 8a10078
Jacob Kaplan-Moss authored May 28, 2010
4  django/http/__init__.py
@@ -177,14 +177,14 @@ def __delitem__(self, key):
177 177
         super(QueryDict, self).__delitem__(key)
178 178
 
179 179
     def __copy__(self):
180  
-        result = self.__class__('', mutable=True)
  180
+        result = self.__class__('', mutable=True, encoding=self.encoding)
181 181
         for key, value in dict.items(self):
182 182
             dict.__setitem__(result, key, value)
183 183
         return result
184 184
 
185 185
     def __deepcopy__(self, memo):
186 186
         import django.utils.copycompat as copy
187  
-        result = self.__class__('', mutable=True)
  187
+        result = self.__class__('', mutable=True, encoding=self.encoding)
188 188
         memo[id(self)] = result
189 189
         for key, value in dict.items(self):
190 190
             dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
16  tests/regressiontests/httpwrappers/tests.py
... ...
@@ -1,5 +1,6 @@
1  
-import unittest
  1
+import copy
2 2
 import pickle
  3
+import unittest
3 4
 from django.http import QueryDict, HttpResponse, CompatCookie, BadHeaderError
4 5
 
5 6
 class QueryDictTests(unittest.TestCase):
@@ -182,6 +183,19 @@ def test_update_from_querydict(self):
182 183
         x.update(y)
183 184
         self.assertEqual(x.getlist('a'), [u'1', u'2', u'3', u'4'])    
184 185
 
  186
+    def test_non_default_encoding(self):
  187
+        """#13572 - QueryDict with a non-default encoding"""
  188
+        q = QueryDict('sbb=one', encoding='rot_13') 
  189
+        self.assertEqual(q.encoding , 'rot_13' )
  190
+        self.assertEqual(q.items() , [(u'foo', u'bar')] )
  191
+        self.assertEqual(q.urlencode() , 'sbb=one' )
  192
+        q = q.copy() 
  193
+        self.assertEqual(q.encoding , 'rot_13' )
  194
+        self.assertEqual(q.items() , [(u'foo', u'bar')] )
  195
+        self.assertEqual(q.urlencode() , 'sbb=one' )
  196
+        self.assertEqual(copy.copy(q).encoding , 'rot_13' )
  197
+        self.assertEqual(copy.deepcopy(q).encoding , 'rot_13')
  198
+        
185 199
 class HttpResponseTests(unittest.TestCase):
186 200
     def test_unicode_headers(self):
187 201
         r = HttpResponse()

0 notes on commit 3180f93

Please sign in to comment.
Something went wrong with that request. Please try again.