Skip to content

Commit ae6faea

Browse files
authored
Merge pull request #349 from yozachar/workshop
fix: regex ignore-case uses only `a-z`
2 parents e3d30f8 + 068d049 commit ae6faea

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/validators/email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def email(
8585
)
8686
if re.match(
8787
# dot-atom
88-
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$"
88+
r"(^[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
8989
# quoted-string
9090
+ r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"$)',
9191
username_part,

src/validators/hostname.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _simple_hostname_regex():
2525
"""Simple hostname validation regex."""
2626
# {0,59} because two characters are already matched at
2727
# the beginning and at the end, making the range {1, 61}
28-
return re.compile(r"^(?!-)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,59}[a-zA-Z0-9])?(?<!-)$")
28+
return re.compile(r"^(?!-)[a-z0-9](?:[a-z0-9-]{0,59}[a-z0-9])?(?<!-)$", re.IGNORECASE)
2929

3030

3131
def _port_validator(value: str):

src/validators/iban.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def iban(value: str, /):
3838
(ValidationError): If `value` is an invalid IBAN code.
3939
"""
4040
return (
41-
(re.match(r"^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$", value) and _mod_check(value))
41+
(re.match(r"^[a-z]{2}[0-9]{2}[a-z0-9]{11,30}$", value, re.IGNORECASE) and _mod_check(value))
4242
if value
4343
else False
4444
)

src/validators/url.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def _username_regex():
1515
return re.compile(
1616
# dot-atom
17-
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$"
17+
r"(^[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
1818
# non-quoted-string
1919
+ r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*$)",
2020
re.IGNORECASE,
@@ -25,7 +25,7 @@ def _username_regex():
2525
def _path_regex():
2626
return re.compile(
2727
# allowed symbols
28-
r"^[\/a-zA-Z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%"
28+
r"^[\/a-z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%"
2929
# emoticons / emoji
3030
+ r"\U0001F600-\U0001F64F"
3131
# multilingual unicode ranges
@@ -133,7 +133,9 @@ def _validate_optionals(path: str, query: str, fragment: str, strict_query: bool
133133
optional_segments &= True
134134
if fragment:
135135
# See RFC3986 Section 3.5 Fragment for allowed characters
136-
optional_segments &= bool(re.fullmatch(r"[0-9a-zA-Z?/:@\-._~%!$&'()*+,;=]*", fragment))
136+
optional_segments &= bool(
137+
re.fullmatch(r"[0-9a-z?/:@\-._~%!$&'()*+,;=]*", fragment, re.IGNORECASE)
138+
)
137139
return optional_segments
138140

139141

0 commit comments

Comments
 (0)