Skip to content

Commit

Permalink
handle URLs without '/' after their TLD (#5252)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Feb 29, 2024
1 parent c006f9c commit 76581c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gallery_dl/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions test/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ def test_ensure_http_scheme(self, f=text.ensure_http_scheme):

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)
Expand Down

0 comments on commit 76581c1

Please sign in to comment.