Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/validators/i18n/fi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _ssn_pattern(ssn_check_marks: str):
(?P<century>[ABCDEFYXWVU+-])
(?P<serial>(\d{{3}}))
(?P<checksum>[{check_marks}])$""".format(check_marks=ssn_check_marks),
re.VERBOSE,
re.VERBOSE | re.ASCII,
)


Expand Down
2 changes: 1 addition & 1 deletion src/validators/i18n/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _ssn_pattern():
r"\s(\d{2,3})" # town of birth
r"\s(\d{3})" # registration number
r"(?:\s(\d{2}))?$", # control key (may or may not be provided)
re.VERBOSE,
re.VERBOSE | re.ASCII,
)


Expand Down
4 changes: 2 additions & 2 deletions src/validators/i18n/ind.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def ind_aadhar(value: str):
(Literal[True]): If `value` is a valid aadhar card number.
(ValidationError): If `value` is an invalid aadhar card number.
"""
return re.fullmatch(r"^[2-9]{1}\d{3}\s\d{4}\s\d{4}$", value)
return re.fullmatch(r"^[2-9]{1}\d{3}\s\d{4}\s\d{4}$", value, re.ASCII)


@validator
Expand All @@ -44,4 +44,4 @@ def ind_pan(value: str):
(Literal[True]): If `value` is a valid PAN card number.
(ValidationError): If `value` is an invalid PAN card number.
"""
return re.fullmatch(r"[A-Z]{5}\d{4}[A-Z]{1}", value)
return re.fullmatch(r"[A-Z]{5}\d{4}[A-Z]{1}", value, re.ASCII)
6 changes: 6 additions & 0 deletions tests/i18n/test_fi.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ def test_ssn_validates_birth_date_in_its_century(birth_date: str, century: str,
checksum = "0123456789ABCDEFHJKLMNPRSTUVWXY"[int(birth_date + serial) % 31]
value = birth_date + century + serial + checksum
assert bool(fi_ssn(value)) is valid


@pytest.mark.parametrize("value", ["1\u06631052-308T", "1310\u06652-308T", "131052-3\u06608T"])
def test_returns_failed_validation_on_non_ascii_digits_in_ssn(value: str):
"""Test returns failed validation when a script other than ASCII supplies the digits."""
assert isinstance(fi_ssn(value), ValidationError)
13 changes: 13 additions & 0 deletions tests/i18n/test_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,16 @@ def test_returns_true_on_valid_department(value: Union[str, int]):
def test_returns_failed_validation_on_invalid_department(value: Union[str, int]):
"""Test returns failed validation on invalid department."""
assert isinstance(fr_department(value), ValidationError)


@pytest.mark.parametrize(
"value",
[
"1 \u06684 12 76 451 089 46", # Arabic-Indic digit
"1 84 12 76 451 089 \uff146", # fullwidth digit
"1\u00a084 12 76 451 089 46", # no-break space
],
)
def test_returns_failed_validation_on_non_ascii_digits_or_spaces_in_ssn(value: str):
"""Test returns failed validation on digits or spaces outside ASCII."""
assert isinstance(fr_ssn(value), ValidationError)
14 changes: 14 additions & 0 deletions tests/i18n/test_ind.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ def test_returns_true_on_valid_ind_pan(value: str):
def test_returns_failed_validation_on_invalid_ind_pan(value: str):
"""Test returns failed validation on invalid ind pan."""
assert isinstance(ind_pan(value), ValidationError)


@pytest.mark.parametrize(
"value", ["3\u066675 9834 6012", "3675 9834 601\uff12", "3675\u00a09834 6012"]
)
def test_returns_failed_validation_on_non_ascii_digits_or_spaces_in_ind_aadhar(value: str):
"""Test returns failed validation on digits or spaces outside ASCII."""
assert isinstance(ind_aadhar(value), ValidationError)


@pytest.mark.parametrize("value", ["ABCDE\u0669999K", "ABCDE999\uff19K"])
def test_returns_failed_validation_on_non_ascii_digits_in_ind_pan(value: str):
"""Test returns failed validation when a script other than ASCII supplies the digits."""
assert isinstance(ind_pan(value), ValidationError)
Loading