Refactor URL validation to use a constant for allowed schemes

This commit is contained in:
davelopez
2025-05-20 23:32:00 +02:00
parent 59fef1f7b5
commit c2fb2547a6
+3 -1
View File
@@ -35,13 +35,15 @@ URLQueryParam: str = Query(
description="The URL of the remote file",
)
ALLOWED_SCHEMES = ("https", "http")
def is_valid_url(url: str) -> bool:
if url.count("://") != 1:
return False # Ensure there is exactly one scheme
try:
parsed = urlparse(url)
return all([parsed.scheme in ("http", "https"), parsed.netloc])
return all([parsed.scheme in ALLOWED_SCHEMES, parsed.netloc])
except ValueError:
return False