mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
11 lines
393 B
Python
11 lines
393 B
Python
def sanitize_url(url: str) -> str:
|
|
# extract host from url and lower case it, remove trailing slash from url
|
|
protocol = url.split("://")[0]
|
|
host = url.split("://")[1].split("/")[0].lower()
|
|
path = (
|
|
url.split("://")[1].split("/", 1)[1].rstrip("/")
|
|
if "/" in url.split("://")[1]
|
|
else ""
|
|
)
|
|
return f"{protocol}://{host}{'/' + path if path else ''}"
|