Skip to content

Commit d9ec2ff

Browse files
JunaidAhamed-7777nandgator
authored andcommitted
Reject non-ASCII case equivalents in IBANs
1 parent 74dc029 commit d9ec2ff

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/validators/iban.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ 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, re.IGNORECASE) and _mod_check(value))
41+
(
42+
re.match(r"^[a-z]{2}[0-9]{2}[a-z0-9]{11,30}$", value, re.IGNORECASE | re.ASCII)
43+
and _mod_check(value)
44+
)
4245
if value
4346
else False
4447
)

‎tests/test_iban.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ def test_returns_true_on_valid_lowercase_iban(value: str):
2323
def test_returns_failed_validation_on_invalid_iban(value: str):
2424
"""Test returns failed validation on invalid iban."""
2525
assert isinstance(iban(value), ValidationError)
26+
27+
28+
@pytest.mark.parametrize("value", ["\u0131T60X0542811101000000123456", "GB82WE\u017fT12345698765432"])
29+
def test_rejects_non_ascii_case_equivalents(value: str):
30+
"""Unicode case equivalents must not pass the ASCII IBAN format check."""
31+
assert isinstance(iban(value), ValidationError)

0 commit comments

Comments
 (0)