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