mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
handle URLs without '/' after their TLD (#5252)
This commit is contained in:
parent
c006f9c949
commit
76581c13f7
@ -59,8 +59,14 @@ def ensure_http_scheme(url, scheme="https://"):
|
||||
def root_from_url(url, scheme="https://"):
|
||||
"""Extract scheme and domain from a URL"""
|
||||
if not url.startswith(("https://", "http://")):
|
||||
try:
|
||||
return scheme + url[:url.index("/")]
|
||||
except ValueError:
|
||||
return scheme + url
|
||||
try:
|
||||
return url[:url.index("/", 8)]
|
||||
except ValueError:
|
||||
return url
|
||||
|
||||
|
||||
def filename_from_url(url):
|
||||
|
@ -121,12 +121,14 @@ class TestText(unittest.TestCase):
|
||||
|
||||
def test_root_from_url(self, f=text.root_from_url):
|
||||
result = "https://example.org"
|
||||
self.assertEqual(f("https://example.org") , result)
|
||||
self.assertEqual(f("https://example.org/") , result)
|
||||
self.assertEqual(f("https://example.org/path"), result)
|
||||
self.assertEqual(f("example.org/") , result)
|
||||
self.assertEqual(f("example.org/path/") , result)
|
||||
|
||||
result = "http://example.org"
|
||||
self.assertEqual(f("http://example.org") , result)
|
||||
self.assertEqual(f("http://example.org/") , result)
|
||||
self.assertEqual(f("http://example.org/path/"), result)
|
||||
self.assertEqual(f("example.org/", "http://") , result)
|
||||
|
Loading…
Reference in New Issue
Block a user