fix(locale): use only valid letters in en_CA postcodes - #3951
Open
MahinAnowar wants to merge 2 commits into
Open
fix(locale): use only valid letters in en_CA postcodes#3951MahinAnowar wants to merge 2 commits into
MahinAnowar wants to merge 2 commits into
Conversation
✅ Deploy Preview for fakerjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
ST-DDT
approved these changes
Jul 27, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #3951 +/- ##
=======================================
Coverage 98.91% 98.91%
=======================================
Files 924 925 +1
Lines 3224 3230 +6
Branches 585 567 -18
=======================================
+ Hits 3189 3195 +6
Misses 31 31
Partials 4 4
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1416
The en_CA postcode patterns use
?for the second and third letters, andreplaceSymbolsexpands?to any letter A-Z. Canadian postal codes never use D, F, I, O, Q or U though, so roughly 41% of generated codes are invalid — I measured 8,195 bad out of 20,000 draws on the current release, which lines up with the theoretical 1-(20/26)² for two unconstrained letter positions. The first letter was already restricted to the valid 18, which is why only the other two leak.The locale already knows the right answer elsewhere:
postcode_by_state.tsusesfromRegExpwith[ABCEGHJ-NPRSTVW-Z], sozipCode({ state: 'ON' })has always been correct while plainzipCode()isn't.So this multiplies the patterns out, which is what you suggested in the thread ("You might have to duplicate some lines... Maybe multiply it out fully"). It's built programmatically like the nl fix in #3888 rather than being a literal 7,200-line list — 18 first letters × 20 × 20. Same shape as #3905 for fr, so this stays locale-data only and doesn't touch
replaceSymbolsor the v11 resolver plans.The letters list also gets W and Z back for the non-first positions, which is why the
locale-datacharacter-inventory snapshot picks up aZand drops the?.Added a test next to the nl/fr ones asserting 1,000 draws all match
/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z] \d[ABCEGHJ-NPRSTV-Z]\d$/— it fails onnextand passes here. Full suite is green after a build (53,135 tests), and against the built bundle 20,000 draws now give 0 invalid.One note: I left the existing
returns zipCode with proper locale formatassertion alone even though its[A-Za-z]classes are loose enough that they never caught this — happy to tighten it if you'd like.