Visitar URL original
fix(isCurrency): match complete currency symbols literally by vhinayindia · Pull Request #2906 · validatorjs/validator.js · GitHub
Skip to content

fix(isCurrency): match complete currency symbols literally - #2906

Draft
vhinayindia wants to merge 1 commit into
validatorjs:masterfrom
vhinayindia:fix/currency-symbol-literals-20261006
Draft

vhinayindia wants to merge 1 commit into
validatorjs:masterfrom
vhinayindia:fix/currency-symbol-literals-20261006

Conversation

@vhinayindia

Copy link
Copy Markdown

Summary

Escape every non-word character in the configured currency symbol, rather than only the first one.

isCurrency currently accepts a different symbol when a later character has a regular-expression meaning. For example:

isCurrency('S/x10.00', { symbol: 'S/.', require_symbol: true }); // true before this change
isCurrency('دxإ10.00', { symbol: 'د.إ', require_symbol: true }); // true before this change

Both should return false, while the corresponding amounts with the exact configured symbols should remain valid. The same issue affects symbols placed after the amount and optional symbols.

This extends the literal-symbol escaping introduced in #1306 by applying the existing replacement globally. No public options or other currency-formatting rules change.

Validation

  • Added three regression tests covering required, optional, and trailing symbols, including a non-ASCII symbol.
  • Confirmed all three regressions fail before the source fix and pass afterward.
  • npm test: all 326 tests pass, including the full build and lint steps, on Node.js 24.19.0.
  • Checked valid and invalid symbol matching in the generated Node entry point, individual Node module, browser bundle, and minified browser bundle.

Checklist

  • PR contains only related source and regression-test changes.
  • README reviewed; the public API and options are unchanged.
  • Regression tests added and the complete test suite passed.
  • Related implementation reference provided above.

@codecov

codecov Bot commented Oct 6, 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 (9018a7f).

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

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