mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-08-23 06:35:51 -07:00
[utils] Fix sanitize_url regression with search queries
Commit 1baa0f5
introduced a regression which caused search queries such as
"ytsearch:search query" to be changed to "ytsearch:search%20query".
This arose when setting the default-search option to "ytsearch"
and when calling the YoutubeDL.extract_info method.
This occurred because sanitize_url, which doesn't always receive a URL,
performs a URL escape. Instead, this escape should be performed in
sanitized_Request, which always receives a URL.
This commit is contained in:
parent
55c823634d
commit
673d407579
2 changed files with 7 additions and 2 deletions
|
@ -65,6 +65,7 @@ from youtube_dl.utils import (
|
|||
sanitize_filename,
|
||||
sanitize_path,
|
||||
sanitize_url,
|
||||
sanitized_Request,
|
||||
expand_path,
|
||||
prepend_extension,
|
||||
replace_extension,
|
||||
|
@ -236,6 +237,10 @@ class TestUtil(unittest.TestCase):
|
|||
self.assertEqual(sanitize_url('httpss://foo.bar'), 'https://foo.bar')
|
||||
self.assertEqual(sanitize_url('rmtps://foo.bar'), 'rtmps://foo.bar')
|
||||
self.assertEqual(sanitize_url('https://foo.bar'), 'https://foo.bar')
|
||||
self.assertEqual(sanitize_url('ytsearch:search query'), 'ytsearch:search query')
|
||||
|
||||
def test_sanitized_Request(self):
|
||||
self.assertEqual(sanitized_Request('https://foo.bar/foo bar').get_full_url(), 'https://foo.bar/foo%20bar')
|
||||
|
||||
def test_expand_path(self):
|
||||
def env(var):
|
||||
|
|
|
@ -2169,11 +2169,11 @@ def sanitize_url(url):
|
|||
for mistake, fixup in COMMON_TYPOS:
|
||||
if re.match(mistake, url):
|
||||
return re.sub(mistake, fixup, url)
|
||||
return escape_url(url)
|
||||
return url
|
||||
|
||||
|
||||
def sanitized_Request(url, *args, **kwargs):
|
||||
return compat_urllib_request.Request(sanitize_url(url), *args, **kwargs)
|
||||
return compat_urllib_request.Request(escape_url(sanitize_url(url)), *args, **kwargs)
|
||||
|
||||
|
||||
def expand_path(s):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue