mirror of https://github.com/yt-dlp/yt-dlp.git
[utils] Escape URLs in `sanitized_Request`, not `sanitize_url`
d2558234cf
added escaping of URLs while sanitizing. However, `sanitize_url` may not always receive an actual URL.
Eg: When using `yt-dlp "search query" --default-search ytsearch`, `search query` gets escaped to `search%20query` before being prefixed with `ytsearch:` which is not the intended behavior. So the escaping is moved to `sanitized_Request` instead.
This commit is contained in:
parent
6e6390321c
commit
bc6b9bcd65
|
@ -239,6 +239,7 @@ class TestUtil(unittest.TestCase):
|
||||||
self.assertEqual(sanitize_url('httpss://foo.bar'), 'https://foo.bar')
|
self.assertEqual(sanitize_url('httpss://foo.bar'), 'https://foo.bar')
|
||||||
self.assertEqual(sanitize_url('rmtps://foo.bar'), 'rtmps://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('https://foo.bar'), 'https://foo.bar')
|
||||||
|
self.assertEqual(sanitize_url('foo bar'), 'foo bar')
|
||||||
|
|
||||||
def test_extract_basic_auth(self):
|
def test_extract_basic_auth(self):
|
||||||
auth_header = lambda url: sanitized_Request(url).get_header('Authorization')
|
auth_header = lambda url: sanitized_Request(url).get_header('Authorization')
|
||||||
|
|
|
@ -2165,7 +2165,7 @@ def sanitize_url(url):
|
||||||
for mistake, fixup in COMMON_TYPOS:
|
for mistake, fixup in COMMON_TYPOS:
|
||||||
if re.match(mistake, url):
|
if re.match(mistake, url):
|
||||||
return re.sub(mistake, fixup, url)
|
return re.sub(mistake, fixup, url)
|
||||||
return escape_url(url)
|
return url
|
||||||
|
|
||||||
|
|
||||||
def extract_basic_auth(url):
|
def extract_basic_auth(url):
|
||||||
|
@ -2181,7 +2181,7 @@ def extract_basic_auth(url):
|
||||||
|
|
||||||
|
|
||||||
def sanitized_Request(url, *args, **kwargs):
|
def sanitized_Request(url, *args, **kwargs):
|
||||||
url, auth_header = extract_basic_auth(sanitize_url(url))
|
url, auth_header = extract_basic_auth(escape_url(sanitize_url(url)))
|
||||||
if auth_header is not None:
|
if auth_header is not None:
|
||||||
headers = args[1] if len(args) >= 2 else kwargs.setdefault('headers', {})
|
headers = args[1] if len(args) >= 2 else kwargs.setdefault('headers', {})
|
||||||
headers['Authorization'] = auth_header
|
headers['Authorization'] = auth_header
|
||||||
|
|
Loading…
Reference in New Issue