Skip to content

fix(isVAT): reject stray comma in DO and VE VAT numbers#2814

Open
simonkundrik wants to merge 2 commits into
validatorjs:masterfrom
simonkundrik:fix/isvat-do-comma
Open

fix(isVAT): reject stray comma in DO and VE VAT numbers#2814
simonkundrik wants to merge 2 commits into
validatorjs:masterfrom
simonkundrik:fix/isvat-do-comma

Conversation

@simonkundrik

@simonkundrik simonkundrik commented Jul 6, 2026

Copy link
Copy Markdown

Problem

Two country matchers in src/lib/isVAT.js use character classes that unintentionally contain a literal comma, so they accept a stray ,:

DO: str => /^(DO)?(\d{11}|(\d{3}-\d{7}-\d{1})|[1,4,5]{1}\d{8}|([1,4,5]{1})-\d{2}-\d{5}-\d{1})$/.test(str),
VE: str => /^(VE)?[J,G,V,E]{1}-(\d{9}|(\d{8}-\d{1}))$/.test(str),

Inside a character class the commas are literals, so [1,4,5] matches 1 , 4 5 and [J,G,V,E] matches J , G V E. This produces false positives:

isVAT(',12345678', 'DO');     // => true (should be false)
isVAT(',-12-34567-8', 'DO');  // => true (should be false)
isVAT(',-123456789', 'VE');   // => true (should be false)
isVAT(',-12345678-9', 'VE');  // => true (should be false)

This is the same class of bug as the [J,Z] character class that was fixed in isISO6346 (#2772).

Fix

  • DO: [1,4,5][145] (both occurrences)
  • VE: [J,G,V,E][JGVE]

Every previously-valid input still validates (they begin with the intended digits/letters); only the stray comma is now rejected.

Tests

Added the comma inputs above to the DO and VE invalid lists in test/validators.test.js.

  • Before the fix: the suite fails, e.g. validator.isVAT(",12345678", "DO") passed but should have failed.
  • After the fix: full suite passes (318 passing), eslint src test is clean, and coverage is unchanged.

Found by auditing the validators for character classes that unintentionally contain a comma.

The `DO` matcher used the character class `[1,4,5]`, which matches a
literal comma in addition to the digits 1, 4 and 5. As a result,
strings beginning with a comma were accepted, e.g.
`isVAT(',12345678', 'DO')` returned `true`.

Use `[145]` instead so only the intended digits are matched, and add
regression tests for the previously-accepted comma inputs.
@codecov

codecov Bot commented Jul 6, 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 (baf8fd5).

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

The `VE` matcher's `[J,G,V,E]` character class has the same
literal-comma bug as `DO`: it accepts a stray comma in addition to the
intended letters J, G, V and E. Use `[JGVE]` and add regression tests.
@simonkundrik simonkundrik changed the title fix(isVAT): reject stray comma in Dominican Republic (DO) VAT numbers fix(isVAT): reject stray comma in DO and VE VAT numbers Jul 6, 2026
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