Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/validators/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def uri(value: str, /):
if not value or re.search(r"[\x00-\x20\x7f]", value):
return False

# schemes are case-insensitive (RFC 3986, section 3.1)
scheme, colon, rest = value.partition(":")
value = scheme.lower() + colon + rest

# TODO: work on various validations

# url
Expand Down
16 changes: 16 additions & 0 deletions tests/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,19 @@ def test_rejects_raw_ascii_controls_and_spaces_in_uri(value: str, invalid_char:
def test_accepts_percent_encoded_characters_in_uri(value: str):
"""Test accepts percent encoded characters in URI."""
assert uri(value)


@pytest.mark.parametrize(
"value",
[
"HTTP://EXAMPLE.COM",
"Https://example.com/path",
"MAILTO:user@example.com",
"FILE:///tmp/readme.txt",
"Telnet://example.com:23",
"URN:isbn:9780140328721",
],
)
def test_accepts_scheme_in_any_case(value: str):
"""Test schemes are case-insensitive (RFC 3986 3.1)."""
assert uri(value)