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
5 changes: 4 additions & 1 deletion src/validators/iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ 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, re.IGNORECASE) and _mod_check(value))
(
re.match(r"^[a-z]{2}[0-9]{2}[a-z0-9]{11,30}$", value, re.IGNORECASE | re.ASCII)
and _mod_check(value)
)
if value
else False
)
6 changes: 6 additions & 0 deletions tests/test_iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ def test_returns_true_on_valid_lowercase_iban(value: str):
def test_returns_failed_validation_on_invalid_iban(value: str):
"""Test returns failed validation on invalid iban."""
assert isinstance(iban(value), ValidationError)


@pytest.mark.parametrize("value", ["\u0131T60X0542811101000000123456", "GB82WE\u017fT12345698765432"])
def test_rejects_non_ascii_case_equivalents(value: str):
"""Unicode case equivalents must not pass the ASCII IBAN format check."""
assert isinstance(iban(value), ValidationError)