[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.
pull/372/head
pukkandan 3 years ago
parent 6e6390321c
commit bc6b9bcd65
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698

@ -239,6 +239,7 @@ 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('foo bar'), 'foo bar')
def test_extract_basic_auth(self):
auth_header = lambda url: sanitized_Request(url).get_header('Authorization')

@ -2165,7 +2165,7 @@ 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 extract_basic_auth(url):
@ -2181,7 +2181,7 @@ def extract_basic_auth(url):
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:
headers = args[1] if len(args) >= 2 else kwargs.setdefault('headers', {})
headers['Authorization'] = auth_header

Loading…
Cancel
Save