Kaydet (Commit) fe873e27 authored tarafından Claude Paroz's avatar Claude Paroz

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

Thanks aneil for the report and the initial patch.
üst a2022dae
......@@ -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)
......
......@@ -31,6 +31,7 @@ class TestUtilsHttp(unittest.TestCase):
# 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 @@ class TestUtilsHttp(unittest.TestCase):
'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'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment