summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2008-08-29 16:49:19 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2008-08-29 16:49:19 +0000
commit6a8dcafb575c3b0147223c04e7ccae553c0c9a49 (patch)
treeefd24a14692b5dfcfbfbfea57a607aadb4343ed6
parentcd0b65bcf79dc61481d94a415a1598bb510d21c9 (diff)
Fixed #8278: fixed `QueryDict.update(QueryDict)`. Thanks, julien.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8705 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/http/__init__.py9
-rw-r--r--tests/regressiontests/httpwrappers/tests.py8
2 files changed, 15 insertions, 2 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py
index ded6d090b1..60b6d15795 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -211,8 +211,13 @@ class QueryDict(MultiValueDict):
def update(self, other_dict):
self._assert_mutable()
f = lambda s: str_to_unicode(s, self.encoding)
- d = dict([(f(k), f(v)) for k, v in other_dict.items()])
- MultiValueDict.update(self, d)
+ if hasattr(other_dict, 'lists'):
+ for key, valuelist in other_dict.lists():
+ for value in valuelist:
+ MultiValueDict.update(self, {f(key): f(value)})
+ else:
+ d = dict([(f(k), f(v)) for k, v in other_dict.items()])
+ MultiValueDict.update(self, d)
def pop(self, key, *args):
self._assert_mutable()
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index b10c24e7bf..844b356366 100644
--- a/tests/regressiontests/httpwrappers/tests.py
+++ b/tests/regressiontests/httpwrappers/tests.py
@@ -436,6 +436,14 @@ Traceback (most recent call last):
...
UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format
+#
+# Regression test for #8278: QueryDict.update(QueryDict)
+#
+>>> x = QueryDict("a=1&a=2", mutable=True)
+>>> y = QueryDict("a=3&a=4")
+>>> x.update(y)
+>>> x.getlist('a')
+[u'1', u'2', u'3', u'4']
"""
from django.http import QueryDict, HttpResponse