Skip to content

fix(isCreditCard): anchor Mastercard regex#2788

Open
TisanSmart232 wants to merge 1 commit into
validatorjs:masterfrom
TisanSmart232:fix-mastercard-prefix-match
Open

fix(isCreditCard): anchor Mastercard regex#2788
TisanSmart232 wants to merge 1 commit into
validatorjs:masterfrom
TisanSmart232:fix-mastercard-prefix-match

Conversation

@TisanSmart232

Copy link
Copy Markdown

Fixes the Mastercard provider regex so it has one set of anchors around the whole expression.

Before this change, the first Mastercard branch was anchored only at the start:

/^5[1-5][0-9]{2}|...$/

That allowed strings that start with a valid 51-55 Mastercard prefix to pass the provider regex even when they have extra trailing digits. If the full string also happens to pass the Luhn check, isCreditCard can return true for an invalid Mastercard length.

Before:

validator.isCreditCard('53982287078715277') // true

After:

validator.isCreditCard('53982287078715277') // false

The change is limited to isCreditCard and adds a regression case for both the default validator path and the explicit { provider: 'Mastercard' } path.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

Tests

  • npm run lint
  • npx mocha --require @babel/register --reporter dot test/validators.test.js --grep "credit cards"
  • npm test

@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 (3d2f4b3) to head (7597f48).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2788   +/-   ##
=========================================
  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