summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSergey M․ <[email protected]>2017-03-06 03:57:46 +0700
committerSergey M․ <[email protected]>2017-03-06 03:57:46 +0700
commit4b5de77bdb7765df4797bf068592926285ba709a (patch)
tree92695bf40e9b18e7558cd439106cece72a309855
parent96182695e4e37795a30ab143129c91dab18a9865 (diff)
downloadyoutube-dl-4b5de77bdb7765df4797bf068592926285ba709a.tar.gz
youtube-dl-4b5de77bdb7765df4797bf068592926285ba709a.zip
[utils] Process bytestrings in urljoin (closes #12369)
-rw-r--r--test/test_utils.py3
-rw-r--r--youtube_dl/utils.py7
2 files changed, 9 insertions, 1 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index aefd94518..173c49514 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.py
index 8738aa249..d293c7498 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 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)