mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-22 18:17:17 -05:00
[utils] Fixup some common URL's typos in sanitize_url (closes #15649)
This commit is contained in:
parent
90830004c8
commit
befa4708fd
@ -57,6 +57,7 @@ from youtube_dl.utils import (
|
|||||||
read_batch_urls,
|
read_batch_urls,
|
||||||
sanitize_filename,
|
sanitize_filename,
|
||||||
sanitize_path,
|
sanitize_path,
|
||||||
|
sanitize_url,
|
||||||
expand_path,
|
expand_path,
|
||||||
prepend_extension,
|
prepend_extension,
|
||||||
replace_extension,
|
replace_extension,
|
||||||
@ -219,6 +220,12 @@ class TestUtil(unittest.TestCase):
|
|||||||
self.assertEqual(sanitize_path('./abc'), 'abc')
|
self.assertEqual(sanitize_path('./abc'), 'abc')
|
||||||
self.assertEqual(sanitize_path('./../abc'), '..\\abc')
|
self.assertEqual(sanitize_path('./../abc'), '..\\abc')
|
||||||
|
|
||||||
|
def test_sanitize_url(self):
|
||||||
|
self.assertEqual(sanitize_url('//foo.bar'), 'http://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('https://foo.bar'), 'https://foo.bar')
|
||||||
|
|
||||||
def test_expand_path(self):
|
def test_expand_path(self):
|
||||||
def env(var):
|
def env(var):
|
||||||
return '%{0}%'.format(var) if sys.platform == 'win32' else '${0}'.format(var)
|
return '%{0}%'.format(var) if sys.platform == 'win32' else '${0}'.format(var)
|
||||||
|
@ -538,10 +538,22 @@ def sanitize_path(s):
|
|||||||
return os.path.join(*sanitized_path)
|
return os.path.join(*sanitized_path)
|
||||||
|
|
||||||
|
|
||||||
# Prepend protocol-less URLs with `http:` scheme in order to mitigate the number of
|
|
||||||
# unwanted failures due to missing protocol
|
|
||||||
def sanitize_url(url):
|
def sanitize_url(url):
|
||||||
return 'http:%s' % url if url.startswith('//') else url
|
# Prepend protocol-less URLs with `http:` scheme in order to mitigate
|
||||||
|
# the number of unwanted failures due to missing protocol
|
||||||
|
if url.startswith('//'):
|
||||||
|
return 'http:%s' % url
|
||||||
|
# Fix some common typos seen so far
|
||||||
|
COMMON_TYPOS = (
|
||||||
|
# https://github.com/rg3/youtube-dl/issues/15649
|
||||||
|
(r'^httpss://', r'https://'),
|
||||||
|
# https://bx1.be/lives/direct-tv/
|
||||||
|
(r'^rmtp([es]?)://', r'rtmp\1://'),
|
||||||
|
)
|
||||||
|
for mistake, fixup in COMMON_TYPOS:
|
||||||
|
if re.match(mistake, url):
|
||||||
|
return re.sub(mistake, fixup, url)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
def sanitized_Request(url, *args, **kwargs):
|
def sanitized_Request(url, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user