Skip to content

fix(fr_ssn): reject zero-padded 3-digit department codes - #590

Open
imsurya26 wants to merge 1 commit into
python-validators:masterfrom
imsurya26:fix/fr-ssn-padded-department
Open

imsurya26 wants to merge 1 commit into
python-validators:masterfrom
imsurya26:fix/fr-ssn-padded-department

Conversation

@imsurya26

Copy link
Copy Markdown

fr_ssn accepts zero-padded 3-digit department codes:

>>> validators.fr_ssn("1 84 12 075 76 481 95")
True
>>> validators.fr_ssn("1 84 12 001 23 481")
True

In a French social security number (NIR), the department of birth is 2 characters (01-95, 2A/2B, 99 for people born abroad); only the overseas departments use 3 digits (971-976, followed by a 2-digit commune). The pattern allowed any \d{2,3}, and fr_department("075") parses it as 75, so 075, 001, ... were accepted.

The department group is now (\d{2}|97\d|2[AB]); fr_department still limits the 3-digit form to 971-976 (970 and 977-979 stay invalid). Existing valid numbers, including the overseas one in the tests, still pass.

Added two invalid cases to tests/i18n/test_fr.py (both fail without the change). tests/i18n and the fr.py doctests pass, and ruff is clean.

Related: #549 also edits fr_ssn (key-less width check) and the same test list, so whichever lands second may need a trivial merge.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant