fix(isVAT): reject stray comma in DO and VE VAT numbers - #2814
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2814 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2587 2608 +21
Branches 656 663 +7
=========================================
+ Hits 2587 2608 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
|
Hi! Friendly nudge on this small one whenever someone gets a chance. All checks are passing. It fixes a couple of |
tux-tn
left a comment
There was a problem hiding this comment.
Nice catch! Thank you for your PR @simonkundrik
There was a problem hiding this comment.
Pull request overview
This PR fixes overly-permissive VAT validation for Dominican Republic (DO) and Venezuela (VE) by removing unintended literal commas from regex character classes in isVAT, and adds regression tests to ensure comma-prefixed inputs are rejected.
Changes:
- Update DO VAT matcher character classes from
[1,4,5]to[145](both occurrences) to prevent matching,. - Update VE VAT matcher character class from
[J,G,V,E]to[JGVE]to prevent matching,. - Add invalid test fixtures for comma-prefixed DO/VE inputs in
test/validators.test.js.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/lib/isVAT.js | Tightens DO/VE VAT regexes by removing unintended comma matches in character classes. |
| test/validators.test.js | Adds regression tests to confirm comma-prefixed DO/VE VAT values are rejected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Sorry for closing the PR. I wanted to cancel the Copilot review, but it looks like doing so also closes the PR. |
Problem
Two country matchers in
src/lib/isVAT.jsuse character classes that unintentionally contain a literal comma, so they accept a stray,:Inside a character class the commas are literals, so
[1,4,5]matches1 , 4 5and[J,G,V,E]matchesJ , G V E. This produces false positives:This is the same class of bug as the
[J,Z]character class that was fixed inisISO6346(#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
DOandVEinvalid lists intest/validators.test.js.validator.isVAT(",12345678", "DO") passed but should have failed.eslint src testis clean, and coverage is unchanged.Found by auditing the validators for character classes that unintentionally contain a comma.