Skip to content

Commit

Permalink
Merge pull request #349 from yozachar/workshop
Browse files Browse the repository at this point in the history
fix: regex ignore-case uses only `a-z`
  • Loading branch information
yozachar committed Apr 2, 2024
2 parents e3d30f8 + 068d049 commit ae6faea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/validators/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def email(
)
if re.match(
# dot-atom
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$"
r"(^[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
# quoted-string
+ r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"$)',
username_part,
Expand Down
2 changes: 1 addition & 1 deletion src/validators/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _simple_hostname_regex():
"""Simple hostname validation regex."""
# {0,59} because two characters are already matched at
# the beginning and at the end, making the range {1, 61}
return re.compile(r"^(?!-)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,59}[a-zA-Z0-9])?(?<!-)$")
return re.compile(r"^(?!-)[a-z0-9](?:[a-z0-9-]{0,59}[a-z0-9])?(?<!-)$", re.IGNORECASE)


def _port_validator(value: str):
Expand Down
2 changes: 1 addition & 1 deletion src/validators/iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def iban(value: str, /):
(ValidationError): If `value` is an invalid IBAN code.
"""
return (
(re.match(r"^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$", value) and _mod_check(value))
(re.match(r"^[a-z]{2}[0-9]{2}[a-z0-9]{11,30}$", value, re.IGNORECASE) and _mod_check(value))
if value
else False
)
8 changes: 5 additions & 3 deletions src/validators/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def _username_regex():
return re.compile(
# dot-atom
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$"
r"(^[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
# non-quoted-string
+ r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*$)",
re.IGNORECASE,
Expand All @@ -25,7 +25,7 @@ def _username_regex():
def _path_regex():
return re.compile(
# allowed symbols
r"^[\/a-zA-Z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%"
r"^[\/a-z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%"
# emoticons / emoji
+ r"\U0001F600-\U0001F64F"
# multilingual unicode ranges
Expand Down Expand Up @@ -133,7 +133,9 @@ def _validate_optionals(path: str, query: str, fragment: str, strict_query: bool
optional_segments &= True
if fragment:
# See RFC3986 Section 3.5 Fragment for allowed characters
optional_segments &= bool(re.fullmatch(r"[0-9a-zA-Z?/:@\-._~%!$&'()*+,;=]*", fragment))
optional_segments &= bool(
re.fullmatch(r"[0-9a-z?/:@\-._~%!$&'()*+,;=]*", fragment, re.IGNORECASE)
)
return optional_segments


Expand Down

0 comments on commit ae6faea

Please sign in to comment.