A feature-rich command-line audio/video downloader
[utils] Process bytestrings in urljoin (closes #12369)
Sergey M․4b5de77bdb77
diff --git a/test/test_utils.py b/test/test_utils.pyindex aefd94518c..173c495146 100644--- a/test/test_utils.py+++ b/test/test_utils.py@@ -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')diff --git a/youtube_dl/utils.py b/youtube_dl/utils.pyindex 8738aa249e..d293c74982 100644--- a/youtube_dl/utils.py+++ b/youtube_dl/utils.py@@ -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 Noneif 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 Nonereturn compat_urlparse.urljoin(base, path)