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: allow custom URL scheme validation #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 5 additions & 2 deletions src/validators/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# standard
from functools import lru_cache
import re
from typing import Optional
from typing import Callable, Optional
from urllib.parse import parse_qs, unquote, urlsplit

# local
Expand Down Expand Up @@ -165,6 +165,7 @@ def url(
private: Optional[bool] = None, # only for ip-addresses
rfc_1034: bool = False,
rfc_2782: bool = False,
validate_scheme: Callable[[str], bool] = _validate_scheme,
):
r"""Return whether or not given value is a valid URL.

Expand Down Expand Up @@ -213,6 +214,8 @@ def url(
rfc_2782:
Domain/Host name is of type service record.
Ref: [RFC 2782](https://www.rfc-editor.org/rfc/rfc2782).
validate_scheme:
Function that validates URL scheme.

Returns:
(Literal[True]): If `value` is a valid url.
Expand All @@ -229,7 +232,7 @@ def url(
return False

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