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
6 changes: 3 additions & 3 deletions src/validators/i18n/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def fr_department(value: typing.Union[str, int]):
if isinstance(value, str):
if value in ("2A", "2B"): # Corsica
return True
try:
value = int(value)
except ValueError:
# int() also takes signs, underscores, surrounding whitespace and non-ASCII digits
if not re.fullmatch(r"[0-9]+", value):
return False
value = int(value)
return 1 <= value <= 19 or 21 <= value <= 95 or 971 <= value <= 976 # Overseas departments


Expand Down
6 changes: 6 additions & 0 deletions tests/i18n/test_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def test_returns_true_on_valid_department(value: Union[str, int]):
("96",),
("20",),
(20,),
(" 75",),
("75\n",),
("+75",),
("7_5",),
("75",), # fullwidth digits
("٧٥",), # Arabic-Indic digits
],
)
def test_returns_failed_validation_on_invalid_department(value: Union[str, int]):
Expand Down
Loading