]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[utils] Process bytestrings in urljoin (closes #12369)
authorSergey M․ <dstftw@gmail.com>
Sun, 5 Mar 2017 20:57:46 +0000 (03:57 +0700)
committerSergey M․ <dstftw@gmail.com>
Sun, 5 Mar 2017 20:57:46 +0000 (03:57 +0700)
test/test_utils.py
youtube_dl/utils.py

index aefd94518c37e8cf1d33f788bbeefbd9470c5f1d..173c495146c4fca68301465300b54a29c0d5bfd8 100644 (file)
@@ -455,6 +455,9 @@ class TestUtil(unittest.TestCase):
 
     def test_urljoin(self):
         self.assertEqual(urljoin('http://foo.de/', '/a/b/c.txt'), 'http://foo.de/a/b/c.txt')
+        self.assertEqual(urljoin(b'http://foo.de/', '/a/b/c.txt'), 'http://foo.de/a/b/c.txt')
+        self.assertEqual(urljoin('http://foo.de/', b'/a/b/c.txt'), 'http://foo.de/a/b/c.txt')
+        self.assertEqual(urljoin(b'http://foo.de/', b'/a/b/c.txt'), 'http://foo.de/a/b/c.txt')
         self.assertEqual(urljoin('//foo.de/', '/a/b/c.txt'), '//foo.de/a/b/c.txt')
         self.assertEqual(urljoin('http://foo.de/', 'a/b/c.txt'), 'http://foo.de/a/b/c.txt')
         self.assertEqual(urljoin('http://foo.de', '/a/b/c.txt'), 'http://foo.de/a/b/c.txt')
index 8738aa249e6a42cb9ed31e730055ab577b3fd41d..d293c74982f2a9f5797f101a7658536c7a800d00 100644 (file)
@@ -1748,11 +1748,16 @@ def base_url(url):
 
 
 def urljoin(base, path):
+    if isinstance(path, bytes):
+        path = path.decode('utf-8')
     if not isinstance(path, compat_str) or not path:
         return None
     if re.match(r'^(?:https?:)?//', path):
         return path
-    if not isinstance(base, compat_str) or not re.match(r'^(?:https?:)?//', base):
+    if isinstance(base, bytes):
+        base = base.decode('utf-8')
+    if not isinstance(base, compat_str) or not re.match(
+            r'^(?:https?:)?//', base):
         return None
     return compat_urlparse.urljoin(base, path)