fix(isISO6346): anchor the pattern and reject a literal comma - #2877
Open
yfwmaniish wants to merge 1 commit into
Open
fix(isISO6346): anchor the pattern and reject a literal comma#2877yfwmaniish wants to merge 1 commit into
yfwmaniish wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2877 +/- ##
=========================================
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.
Closes #2772.
Bug
isISO6346(and its aliasisFreightContainerID) accepts malformed strings because its regex has two flaws:|splits the whole pattern, so^anchors only the first branch and$only the second. Anything starting with[A-Z]{3}U+ 7 digits matches regardless of trailing junk, and anything ending with[JZ]+ 6-7 digits matches regardless of leading junk.[J,Z]matchesJ,Z, or,.Inputs whose length isn't 11 skip the checksum and return
true, so malformed strings pass:Fix
Group the alternation under the shared
^[A-Z]{3}prefix and end anchor, and drop the stray comma:Tests
Added trailing-junk, leading-junk, and literal-comma cases to the invalid list. Verified against the full existing suite: all 10 valid IDs (incl. the
QJRZ123456J/Z 6-digit case) stay valid and all invalid IDs (incl. the 3 new ones) are rejected.