Skip to content

Commit 8938aa9

Browse files
fix(uri): treat the scheme case-insensitively
`uri` compared scheme prefixes on the raw value, so `HTTP://EXAMPLE.COM` was rejected although `url` accepts it. RFC 3986 3.1: schemes are case-insensitive. Lower-case the scheme before dispatching. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 22786cc commit 8938aa9

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎src/validators/uri.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def uri(value: str, /):
9292
if not value or re.search(r"[\x00-\x20\x7f]", value):
9393
return False
9494

95+
# schemes are case-insensitive (RFC 3986, section 3.1)
96+
scheme, colon, rest = value.partition(":")
97+
value = scheme.lower() + colon + rest
98+
9599
# TODO: work on various validations
96100

97101
# url

‎tests/test_uri.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,19 @@ def test_rejects_raw_ascii_controls_and_spaces_in_uri(value: str, invalid_char:
7373
def test_accepts_percent_encoded_characters_in_uri(value: str):
7474
"""Test accepts percent encoded characters in URI."""
7575
assert uri(value)
76+
77+
78+
@pytest.mark.parametrize(
79+
"value",
80+
[
81+
"HTTP://EXAMPLE.COM",
82+
"Https://example.com/path",
83+
"MAILTO:user@example.com",
84+
"FILE:///tmp/readme.txt",
85+
"Telnet://example.com:23",
86+
"URN:isbn:9780140328721",
87+
],
88+
)
89+
def test_accepts_scheme_in_any_case(value: str):
90+
"""Test schemes are case-insensitive (RFC 3986 3.1)."""
91+
assert uri(value)

0 commit comments

Comments
 (0)