fix(isISO6346): anchor the whole pattern and drop the stray comma - #2857
Open
rajanpanth wants to merge 1 commit into
Open
fix(isISO6346): anchor the whole pattern and drop the stray comma#2857rajanpanth wants to merge 1 commit into
rajanpanth wants to merge 1 commit into
Conversation
The alternation was not grouped, so the start anchor applied only to the U branch and the end anchor only to the J/Z branch. Strings with trailing junk after a U serial, leading junk before a J/Z serial, and a literal comma as the category identifier all validated. The J/Z branch also never required the three-letter owner code. Fixes validatorjs#2772
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2857 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2599 2599
Branches 658 658
=========================================
Hits 2599 2599 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #2772.
The ISO 6346 pattern's alternation was not grouped:
/^[A-Z]{3}(U[0-9]{7})|([J,Z][0-9]{6,7})$/so
^anchored only the U branch and$only the J/Z branch, and[J,Z]contained a literal comma. Three classes of malformed input validated:Inputs whose length is not 11 skip the check-digit computation entirely, so these returned
truewith no checksum at all.The corrected pattern groups the alternation, drops the comma, and requires the three-letter owner code on the J/Z branch too, which the standard mandates for all containers:
/^[A-Z]{3}(?:U[0-9]{7}|[JZ][0-9]{6,7})$/All existing fixtures pass unchanged, including
QJRZ123456(J/Z with 6 digits, no check digit) and the checksum-digit-10 cases. Three regression inputs added to the invalid lists of bothisISO6346andisFreightContainerID.Verification: 252 passing; reverting the source change alone and rebuilding fails exactly the 2 updated test blocks.