Skip to content

fix(isISO6346): anchor the whole pattern and drop the stray comma - #2857

Open
rajanpanth wants to merge 1 commit into
validatorjs:masterfrom
rajanpanth:fix/iso6346-anchoring
Open

fix(isISO6346): anchor the whole pattern and drop the stray comma#2857
rajanpanth wants to merge 1 commit into
validatorjs:masterfrom
rajanpanth:fix/iso6346-anchoring

Conversation

@rajanpanth

Copy link
Copy Markdown

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:

isISO6346('ABCU1234567HELLO') // true: trailing junk ignored by the U branch
isISO6346('JUNKJ1234567')     // true: leading junk ignored by the J/Z branch
isISO6346('AB,1234567')       // true: comma accepted as a category identifier

Inputs whose length is not 11 skip the check-digit computation entirely, so these returned true with 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 both isISO6346 and isFreightContainerID.

Verification: 252 passing; reverting the source change alone and rebuilding fails exactly the 2 updated test blocks.

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

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a79ff98) to head (8ca6048).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

isISO6346 and isFreightContainerID accept malformed strings

1 participant