Skip to content

fix(isPassportNumber): anchor MZ and PH alternations#2790

Open
chatman-media wants to merge 1 commit into
validatorjs:masterfrom
chatman-media:fix/passport-mz-ph-anchoring
Open

fix(isPassportNumber): anchor MZ and PH alternations#2790
chatman-media wants to merge 1 commit into
validatorjs:masterfrom
chatman-media:fix/passport-mz-ph-anchoring

Conversation

@chatman-media

Copy link
Copy Markdown

The Mozambique and Philippines passport patterns put the | outside the anchors, so ^ only applied to the first branch and $ only to the last. That meant any extra characters before or after a valid number slipped through:

isPassportNumber('AB0808212XXXX', 'MZ'); // true, should be false
isPassportNumber('ZZZZ08AB12123', 'MZ'); // true, should be false
isPassportNumber('X123456ZZZ', 'PH');    // true, should be false
isPassportNumber('ZZZXY123456', 'PH');   // true, should be false

Wrapping each alternation in a group so both anchors bind to every branch — same shape as the CA/CN/EE entries already use. All the existing valid/invalid fixtures still behave the same; I added the junk-padded cases above to the MZ and PH tests so the regression is covered.

The Mozambique and Philippines patterns put the alternation outside the
anchors, so ^ bound only to the first branch and $ only to the last.
That let arbitrary leading/trailing characters slip through, e.g.
isPassportNumber('AB0808212XXXX', 'MZ') and
isPassportNumber('X123456ZZZ', 'PH') returned true. Wrapping each
alternation in a group fixes it, matching how CA/CN/EE are already
written. Added the junk-padded cases to the test fixtures.
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a38f15b) to head (de8e514).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2790   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2587      2587           
  Branches       656       656           
=========================================
  Hits          2587      2587           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

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