Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add extra schemes to url validation #396

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/validators/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _path_regex():
)


def _validate_scheme(value: str):
def _validate_scheme(value: str, extra_schemes: set[str] = set()):
"""Validate scheme."""
# More schemes will be considered later.
return (
Expand All @@ -49,7 +49,7 @@ def _validate_scheme(value: str):
"ftp", "ftps", "git", "http", "https",
"irc", "rtmp", "rtmps", "rtsp", "sftp",
"ssh", "telnet",
}
} | extra_schemes
# fmt: on
if value
else False
Expand Down Expand Up @@ -164,6 +164,7 @@ def url(
private: Optional[bool] = None, # only for ip-addresses
rfc_1034: bool = False,
rfc_2782: bool = False,
extra_schemes: set[str] = set()
):
r"""Return whether or not given value is a valid URL.

Expand Down Expand Up @@ -228,7 +229,7 @@ def url(
return False

return (
_validate_scheme(scheme)
_validate_scheme(scheme, extra_schemes=extra_schemes)
and _validate_netloc(
netloc,
skip_ipv6_addr,
Expand Down