[utils] accept only supported protocols in url_or_none
authorRemita Amine <remitamine@gmail.com>
Wed, 30 Dec 2020 08:22:30 +0000 (09:22 +0100)
committerRemita Amine <remitamine@gmail.com>
Wed, 30 Dec 2020 08:22:30 +0000 (09:22 +0100)
test/test_utils.py
youtube_dl/utils.py

index 925a21d341ade5e1da87298f3ca7bc766c2df926..d49d3239c3013c25d40e7cbc99ff567e144b3942 100644 (file)
@@ -554,6 +554,11 @@ class TestUtil(unittest.TestCase):
         self.assertEqual(url_or_none('http$://foo.de'), None)
         self.assertEqual(url_or_none('http://foo.de'), 'http://foo.de')
         self.assertEqual(url_or_none('//foo.de'), '//foo.de')
+        self.assertEqual(url_or_none('s3://foo.de'), None)
+        self.assertEqual(url_or_none('rtmpte://foo.de'), 'rtmpte://foo.de')
+        self.assertEqual(url_or_none('mms://foo.de'), 'mms://foo.de')
+        self.assertEqual(url_or_none('rtspu://foo.de'), 'rtspu://foo.de')
+        self.assertEqual(url_or_none('ftps://foo.de'), 'ftps://foo.de')
 
     def test_parse_age_limit(self):
         self.assertEqual(parse_age_limit(None), None)
index 8cefafd79795c5b1d65ee9bdb757789fef5136e3..d5fb6fd24c3bbbe99ab8c843cc95e44f5326ee67 100644 (file)
@@ -3640,7 +3640,7 @@ def url_or_none(url):
     if not url or not isinstance(url, compat_str):
         return None
     url = url.strip()
-    return url if re.match(r'^(?:[a-zA-Z][\da-zA-Z.+-]*:)?//', url) else None
+    return url if re.match(r'^(?:(?:https?|rt(?:m(?:pt?[es]?|fp)|sp[su]?)|mms|ftps?):)?//', url) else None
 
 
 def parse_duration(s):