Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #12140 -- Fixed http.urlencode result for empty lists

Thanks aneil for the report and the initial patch.
  • Loading branch information...
commit fe873e276527534b3c0c22f457ee314cf029ced4 1 parent a2022da
@claudep claudep authored
Showing with 9 additions and 1 deletion.
  1. +1 −1  django/utils/http.py
  2. +8 −0 tests/regressiontests/utils/http.py
View
2  django/utils/http.py
@@ -71,7 +71,7 @@ def urlencode(query, doseq=0):
query = query.items()
return urllib.urlencode(
[(smart_str(k),
- isinstance(v, (list,tuple)) and [smart_str(i) for i in v] or smart_str(v))
+ [smart_str(i) for i in v] if isinstance(v, (list,tuple)) else smart_str(v))
for k, v in query],
doseq)
View
8 tests/regressiontests/utils/http.py
@@ -31,6 +31,7 @@ def test_urlencode(self):
# 2-tuples (the norm)
result = http.urlencode((('a', 1), ('b', 2), ('c', 3)))
self.assertEqual(result, 'a=1&b=2&c=3')
+
# A dictionary
result = http.urlencode({ 'a': 1, 'b': 2, 'c': 3})
acceptable_results = [
@@ -44,6 +45,13 @@ def test_urlencode(self):
'c=3&b=2&a=1'
]
self.assertTrue(result in acceptable_results)
+ result = http.urlencode({'a': [1, 2]}, doseq=False)
+ self.assertEqual(result, 'a=%5B%271%27%2C+%272%27%5D')
+ result = http.urlencode({'a': [1, 2]}, doseq=True)
+ self.assertEqual(result, 'a=1&a=2')
+ result = http.urlencode({'a': []}, doseq=True)
+ self.assertEqual(result, '')
+
# A MultiValueDict
result = http.urlencode(MultiValueDict({
'name': ['Adrian', 'Simon'],
Please sign in to comment.
Something went wrong with that request. Please try again.