Skip to content

fix(locale): only generate valid French postal codes - #3905

Merged
ST-DDT merged 1 commit into
faker-js:nextfrom
MahinAnowar:fix/fr-postcode-valid-departments
Jun 23, 2026
Merged

ST-DDT merged 1 commit into
faker-js:nextfrom
MahinAnowar:fix/fr-postcode-valid-departments

Conversation

@MahinAnowar

Copy link
Copy Markdown
Contributor

Closes #3550.

Problem

The French (fr) postcode definition is:

export default ['#####'];

# is replaced by any digit, so fakerFR.location.zipCode() generates any 5-digit string — including ranges that are not valid French postal codes and fail validation (e.g. validator.isPostalCode(code, 'FR')):

  • 00000–00999
  • 96000–96999
  • 99000–99999

French postal codes start with a department prefix: metropolitan departments use 01–95, and the overseas departments/collectivities use 971–978, 984 and 986–989.

Fix

Build the pattern array from the real department prefixes (metropolitan 01###–95###, overseas 971##–978##, 984##, 986##–989##), so the unassigned 00xxx / 96xxx / 99xxx ranges are never produced. This mirrors the approach of the recently merged nl postcode fix (#3888) — patterns are generated programmatically rather than hard-coded.

Tests

Adds a regression test (should only return valid department prefixes for fr locale) modeled on the existing nl test: over 1000 samples it asserts each fakerFR.location.zipCode() is 5 digits and starts with a valid metropolitan (01–95) or overseas (971–978/984/986–989) prefix. It fails on the current definition (which produces 00/96/99 prefixes) and passes with this change. The full location suite (2417 tests) passes, pnpm run generate:locales reports no further changes, and ESLint/Prettier are clean.

The fr postcode definition was `['#####']`, which produces any 5-digit
string, including the unassigned 00xxx, 96xxx and 99xxx ranges that fail
postal-code validation. Build the patterns from the real department prefixes
instead — metropolitan 01-95 and overseas 971-978/984/986-989 — mirroring the
nl postcode fix (#3888). Closes #3550.
@MahinAnowar
MahinAnowar requested a review from a team as a code owner June 22, 2026 13:00
@netlify

netlify Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3fb4b4e
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a3931fb7f8089000867f698
😎 Deploy Preview https://deploy-preview-3905.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@ST-DDT ST-DDT added p: 1-normal Nothing urgent c: locale Permutes locale definitions m: location Something is referring to the location module labels Jun 22, 2026
@ST-DDT ST-DDT added this to the v10.x milestone Jun 22, 2026
@ST-DDT
ST-DDT requested a review from Copilot June 22, 2026 13:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes French (fr) locale postal code generation so fakerFR.location.zipCode() only produces department-prefixed 5‑digit codes that fall within valid French postcode ranges, addressing validation failures reported in #3550.

Changes:

  • Replace the fr locale postcode definition with programmatically generated patterns covering metropolitan (01###–95###) and overseas (971##–978##, 984##, 986##–989##) prefixes.
  • Add a regression test that samples 1000 generated French zip codes and asserts they’re 5 digits and start with an allowed prefix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/locales/fr/location/postcode.ts Generates postcode patterns from valid metropolitan and overseas department/territory prefixes to avoid invalid ranges.
test/modules/location.spec.ts Adds a regression test ensuring fakerFR.location.zipCode() only yields 5-digit codes with valid French prefixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.84%. Comparing base (bd23594) to head (3fb4b4e).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3905   +/-   ##
=======================================
  Coverage   98.84%   98.84%           
=======================================
  Files         913      914    +1     
  Lines        3209     3215    +6     
  Branches      574      574           
=======================================
+ Hits         3172     3178    +6     
  Misses         33       33           
  Partials        4        4           
Files with missing lines Coverage Δ
src/locales/fr/location/postcode.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ST-DDT
ST-DDT added this pull request to the merge queue Jun 23, 2026
Merged via the queue into faker-js:next with commit 711f36f Jun 23, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: locale Permutes locale definitions m: location Something is referring to the location module p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid zip/postal codes when using locale fr_FR

4 participants