diff --git a/src/validators/i18n/fr.py b/src/validators/i18n/fr.py index 5552ef61..0d905dd4 100644 --- a/src/validators/i18n/fr.py +++ b/src/validators/i18n/fr.py @@ -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 diff --git a/tests/i18n/test_fr.py b/tests/i18n/test_fr.py index f25c87c5..9a65895a 100644 --- a/tests/i18n/test_fr.py +++ b/tests/i18n/test_fr.py @@ -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]):