fix(isVAT): reject stray comma in DO and VE VAT numbers#2814
Open
simonkundrik wants to merge 2 commits into
Open
fix(isVAT): reject stray comma in DO and VE VAT numbers#2814simonkundrik wants to merge 2 commits into
simonkundrik wants to merge 2 commits into
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 2587
Branches 656 656
=========================================
Hits 2587 2587 ☔ 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.