Skip to content

fix(isISO6346): group alternation and drop comma from class so malformed strings are rejected - #2855

Open
stevechen256-source wants to merge 1 commit into
validatorjs:masterfrom
stevechen256-source:fix/isISO6346-anchoring
Open

fix(isISO6346): group alternation and drop comma from class so malformed strings are rejected#2855
stevechen256-source wants to merge 1 commit into
validatorjs:masterfrom
stevechen256-source:fix/isISO6346-anchoring

Conversation

@stevechen256-source

Copy link
Copy Markdown

What & Why

isISO6346 (aliased isFreightContainerID) 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 the U.../[JZ]... alternation in a single group inside the anchors, and change [J,Z] to [JZ].

Test plan

  • mocha --grep "ISO6346" passes (4 passing).
  • Full suite passes: 252 passing, 0 failing.
  • isISO6346("ABCU1234567HELLO"), isISO6346("CSQU3054383XXX"), isISO6346("hellozZ123456"), isISO6346("AB,123456")false.
  • isISO6346("CSQU3054383") and isISO6346("HLXU2008419")true (unchanged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant