mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 02:04:04 +08:00
Refactor URL validation to use a constant for allowed schemes
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user