fix(isISO6346): group alternation and drop comma from class so malformed strings are rejected - #2855
Open
stevechen256-source wants to merge 1 commit into
Conversation
…med strings are rejected
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.
What & Why
isISO6346(aliasedisFreightContainerID) accepted malformed container codes because its regex alternation was not enclosed in the^...$anchors, and the[J,Z]class accidentally admitted a literal comma. This let inputs with trailing junk ("ABCU1234567HELLO","CSQU3054383XXX"), missing owner prefix ("hellozZ123456"), or a comma ("AB,123456") pass validation — wrong for shipping/logistics code checks.Changes
src/lib/isISO6346.js: wrap theU.../[JZ]...alternation in a single group inside the anchors, and change[J,Z]to[JZ].Test plan
mocha --grep "ISO6346"passes (4 passing).isISO6346("ABCU1234567HELLO"),isISO6346("CSQU3054383XXX"),isISO6346("hellozZ123456"),isISO6346("AB,123456")→false.isISO6346("CSQU3054383")andisISO6346("HLXU2008419")→true(unchanged).