1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

handle URLs without '/' after their TLD (#5252)

This commit is contained in:
Mike Fährmann 2024-02-29 15:05:46 +01:00
parent c006f9c949
commit 76581c13f7
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 10 additions and 2 deletions

View File

@ -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://")):
return scheme + url[:url.index("/")]
return url[:url.index("/", 8)]
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):

View File

@ -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)