Skip to content

Commit

Permalink
Fixed #13572: copies of QueryDicts now have their encoding set correc…
Browse files Browse the repository at this point in the history
…tly.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13314 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jacobian committed May 28, 2010
1 parent 8a10078 commit 3180f93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions django/http/__init__.py
Expand Up @@ -177,14 +177,14 @@ def __delitem__(self, key):
super(QueryDict, self).__delitem__(key)

def __copy__(self):
result = self.__class__('', mutable=True)
result = self.__class__('', mutable=True, encoding=self.encoding)
for key, value in dict.items(self):
dict.__setitem__(result, key, value)
return result

def __deepcopy__(self, memo):
import django.utils.copycompat as copy
result = self.__class__('', mutable=True)
result = self.__class__('', mutable=True, encoding=self.encoding)
memo[id(self)] = result
for key, value in dict.items(self):
dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
Expand Down
16 changes: 15 additions & 1 deletion tests/regressiontests/httpwrappers/tests.py
@@ -1,5 +1,6 @@
import unittest
import copy
import pickle
import unittest
from django.http import QueryDict, HttpResponse, CompatCookie, BadHeaderError

class QueryDictTests(unittest.TestCase):
Expand Down Expand Up @@ -182,6 +183,19 @@ def test_update_from_querydict(self):
x.update(y)
self.assertEqual(x.getlist('a'), [u'1', u'2', u'3', u'4'])

def test_non_default_encoding(self):
"""#13572 - QueryDict with a non-default encoding"""
q = QueryDict('sbb=one', encoding='rot_13')
self.assertEqual(q.encoding , 'rot_13' )
self.assertEqual(q.items() , [(u'foo', u'bar')] )
self.assertEqual(q.urlencode() , 'sbb=one' )
q = q.copy()
self.assertEqual(q.encoding , 'rot_13' )
self.assertEqual(q.items() , [(u'foo', u'bar')] )
self.assertEqual(q.urlencode() , 'sbb=one' )
self.assertEqual(copy.copy(q).encoding , 'rot_13' )
self.assertEqual(copy.deepcopy(q).encoding , 'rot_13')

class HttpResponseTests(unittest.TestCase):
def test_unicode_headers(self):
r = HttpResponse()
Expand Down

0 comments on commit 3180f93

Please sign in to comment.