[compat] Handle tuples properly in urlencode()
authorYen Chi Hsuan <yan12125@gmail.com>
Wed, 6 Apr 2016 10:29:54 +0000 (18:29 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Wed, 6 Apr 2016 10:29:54 +0000 (18:29 +0800)
Fixes #9055

test/test_compat.py
youtube_dl/compat.py

index cc105807a3faf0c4a686534cacfaf1d6300f7eb8..618668210f62191da7f899a2a586c699b512c129 100644 (file)
@@ -76,6 +76,10 @@ class TestCompat(unittest.TestCase):
         self.assertEqual(compat_urllib_parse_urlencode({'abc': b'def'}), 'abc=def')
         self.assertEqual(compat_urllib_parse_urlencode({b'abc': 'def'}), 'abc=def')
         self.assertEqual(compat_urllib_parse_urlencode({b'abc': b'def'}), 'abc=def')
+        self.assertEqual(compat_urllib_parse_urlencode([('abc', 'def')]), 'abc=def')
+        self.assertEqual(compat_urllib_parse_urlencode([('abc', b'def')]), 'abc=def')
+        self.assertEqual(compat_urllib_parse_urlencode([(b'abc', 'def')]), 'abc=def')
+        self.assertEqual(compat_urllib_parse_urlencode([(b'abc', b'def')]), 'abc=def')
 
     def test_compat_shlex_split(self):
         self.assertEqual(compat_shlex_split('-option "one two"'), ['-option', 'one two'])
index 76b6b0e3838c65c2d5814d0206c18dfe713d6435..0b6c5ca7a8ba5eb6cb064916d56a5ca8eae32003 100644 (file)
@@ -181,7 +181,8 @@ except ImportError:  # Python 2
             if isinstance(e, dict):
                 e = encode_dict(e)
             elif isinstance(e, (list, tuple,)):
-                e = encode_list(e)
+                list_e = encode_list(e)
+                e = tuple(list_e) if isinstance(e, tuple) else list_e
             elif isinstance(e, compat_str):
                 e = e.encode(encoding)
             return e