Skip to content

Commit 8ae705d

Browse files
Jordan-Bourillotnandgator
authored andcommitted
fix(i18n/fr): reject comma as gender/Corsica suffix in fr_ssn
The SSN regex used the character classes [1,2] and 2[A,B], which also match a literal comma. fr_ssn(', 84 12 76 451 089') was therefore accepted as valid. Drop the commas ([12] and [AB]); valid SSNs are unaffected.
1 parent ffc28ed commit 8ae705d

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

‎src/validators/i18n/fr.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
def _ssn_pattern():
1414
"""SSN Pattern."""
1515
return re.compile(
16-
r"^([1,2])" # gender (1=M, 2=F)
16+
r"^([12])" # gender (1=M, 2=F)
1717
r"\s(\d{2})" # year of birth
1818
r"\s(0[1-9]|1[0-2])" # month of birth
19-
r"\s(\d{2,3}|2[A,B])" # department of birth
19+
r"\s(\d{2,3}|2[AB])" # department of birth
2020
r"\s(\d{2,3})" # town of birth
2121
r"\s(\d{3})" # registration number
2222
r"(?:\s(\d{2}))?$", # control key (may or may not be provided)

‎tests/i18n/test_fr.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_returns_true_on_valid_ssn(value: str):
3434
(None,),
3535
("",),
3636
("3 84 12 76 451 089 46",), # wrong gender number
37+
(", 84 12 76 451 089",), # comma is not a valid gender (regex char-class bug)
3738
("1 84 12 76 451 089 47",), # wrong control key
3839
("1 84 00 76 451 089",), # invalid month
3940
("1 84 13 76 451 089",), # invalid month

0 commit comments

Comments
 (0)