Skip to content

Commit f0eae3d

Browse files
fix(i18n/ind): anchor ind_pan so trailing characters are rejected
ind_pan used re.match(r"[A-Z]{5}\d{4}[A-Z]{1}", ...) with no trailing $, so any string starting with a valid PAN was accepted -- e.g. ind_pan('ABCDE9999KEXTRA') returned a match. Anchor the pattern with ^...$, matching the ind_aadhar style just above it.
1 parent 2d0074a commit f0eae3d

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/validators/i18n/ind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ def ind_pan(value: str):
4444
(Literal[True]): If `value` is a valid PAN card number.
4545
(ValidationError): If `value` is an invalid PAN card number.
4646
"""
47-
return re.match(r"[A-Z]{5}\d{4}[A-Z]{1}", value)
47+
return re.match(r"^[A-Z]{5}\d{4}[A-Z]{1}$", value)

tests/i18n/test_ind.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def test_returns_true_on_valid_ind_pan(value: str):
2626
assert ind_pan(value)
2727

2828

29-
@pytest.mark.parametrize("value", ["ABC5d7896B", "417598346012", "AaaPL1234C"])
29+
@pytest.mark.parametrize(
30+
"value", ["ABC5d7896B", "417598346012", "AaaPL1234C", "ABCDE9999KEXTRA"]
31+
)
3032
def test_returns_failed_validation_on_invalid_ind_pan(value: str):
3133
"""Test returns failed validation on invalid ind pan."""
3234
assert isinstance(ind_pan(value), ValidationError)

0 commit comments

Comments
 (0)