Skip to content

A feature-rich command-line audio/video downloader

[utils] `base_url`: URL paths can contain `&` (#4841)

Elyse7657ec7ed631
diff --git a/test/test_utils.py b/test/test_utils.py
index 67cd966d8e..96477c53fc 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -566,6 +566,7 @@ class TestUtil(unittest.TestCase):
self.assertEqual(base_url('http://foo.de/bar/'), 'http://foo.de/bar/')
self.assertEqual(base_url('http://foo.de/bar/baz'), 'http://foo.de/bar/')
self.assertEqual(base_url('http://foo.de/bar/baz?x=z/x/c'), 'http://foo.de/bar/')
+ self.assertEqual(base_url('http://foo.de/bar/baz&x=z&w=y/x/c'), 'http://foo.de/bar/baz&x=z&w=y/x/')
def test_urljoin(self):
self.assertEqual(urljoin('http://foo.de/', '/a/b/c.txt'), 'http://foo.de/a/b/c.txt')
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index 90042aa8b9..53939f2902 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -2479,7 +2479,7 @@ def url_basename(url):
def base_url(url):
- return re.match(r'https?://[^?#&]+/', url).group()
+ return re.match(r'https?://[^?#]+/', url).group()
def urljoin(base, path):