Code

Ticket #12140: 12140-2.diff

File 12140-2.diff, 1.6 KB (added by claudep, 2 years ago)

Patch updated to current trunk

Line 
1diff --git a/django/utils/http.py b/django/utils/http.py
2index d343a37..9da5a14 100644
3--- a/django/utils/http.py
4+++ b/django/utils/http.py
5@@ -71,7 +71,7 @@ def urlencode(query, doseq=0):
6         query = query.items()
7     return urllib.urlencode(
8         [(smart_str(k),
9-         isinstance(v, (list,tuple)) and [smart_str(i) for i in v] or smart_str(v))
10+         [smart_str(i) for i in v] if isinstance(v, (list,tuple)) else smart_str(v))
11             for k, v in query],
12         doseq)
13 
14diff --git a/tests/regressiontests/utils/http.py b/tests/regressiontests/utils/http.py
15index 16c7daa..67dcd7a 100644
16--- a/tests/regressiontests/utils/http.py
17+++ b/tests/regressiontests/utils/http.py
18@@ -31,6 +31,7 @@ class TestUtilsHttp(unittest.TestCase):
19         # 2-tuples (the norm)
20         result = http.urlencode((('a', 1), ('b', 2), ('c', 3)))
21         self.assertEqual(result, 'a=1&b=2&c=3')
22+
23         # A dictionary
24         result = http.urlencode({ 'a': 1, 'b': 2, 'c': 3})
25         acceptable_results = [
26@@ -44,6 +45,13 @@ class TestUtilsHttp(unittest.TestCase):
27             'c=3&b=2&a=1'
28         ]
29         self.assertTrue(result in acceptable_results)
30+        result = http.urlencode({'a': [1, 2]}, doseq=False)
31+        self.assertEqual(result, 'a=%5B%271%27%2C+%272%27%5D')
32+        result = http.urlencode({'a': [1, 2]}, doseq=True)
33+        self.assertEqual(result, 'a=1&a=2')
34+        result = http.urlencode({'a': []}, doseq=True)
35+        self.assertEqual(result, '')
36+
37         # A MultiValueDict
38         result = http.urlencode(MultiValueDict({
39             'name': ['Adrian', 'Simon'],