Skip to content

fix(isCreditCard): anchor Mastercard regex so short strings are rejected - #2966

Closed
FullStraing wants to merge 1 commit into
validatorjs:masterfrom
FullStraing:fix/isCreditCard-mastercard-anchoring
Closed

FullStraing wants to merge 1 commit into
validatorjs:masterfrom
FullStraing:fix/isCreditCard-mastercard-anchoring

Conversation

@FullStraing

Copy link
Copy Markdown

The Mastercard regex was parsed as two alternatives because | binds looser than ^/$: ^5[1-5][0-9]{2} matched any string starting with 51-55, so isCreditCard('5108') returned true. Wrapping the alternation in a non-capturing group anchors both branches, requiring exactly 16 digits. Regression tests added for '5108' (with and without the mastercard provider).
Fixes #2717.

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (1b3ae07).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2966   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2599           
  Branches       658       658           
=========================================
  Hits          2599      2599           

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

@FullStraing

Copy link
Copy Markdown
Author

Closing as a duplicate of #2942, which already fixes #2717 with the same anchoring fix and tests (opened Oct 21 by @tyza66). Leaving this here for reference.

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.

isCreditCard: Mastercard regex anchoring bug accepts 4-digit and partial strings

1 participant