From 8ca6048938beac4633d3e5de39b1bcfcbb4e55f0 Mon Sep 17 00:00:00 2001 From: rajanpanth Date: Sat, 22 Aug 2026 16:18:00 +0545 Subject: [PATCH] fix(isISO6346): anchor the whole pattern and drop the stray comma 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 #2772 --- src/lib/isISO6346.js | 2 +- test/validators.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/isISO6346.js b/src/lib/isISO6346.js index 2c28c1123..597f0b2fd 100644 --- a/src/lib/isISO6346.js +++ b/src/lib/isISO6346.js @@ -3,7 +3,7 @@ import assertString from './util/assertString'; // https://en.wikipedia.org/wiki/ISO_6346 // according to ISO6346 standard, checksum digit is mandatory for freight container but recommended // for other container types (J and Z) -const isISO6346Str = /^[A-Z]{3}(U[0-9]{7})|([J,Z][0-9]{6,7})$/; +const isISO6346Str = /^[A-Z]{3}(?:U[0-9]{7}|[JZ][0-9]{6,7})$/; const isDigit = /^[0-9]$/; export function isISO6346(str) { diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..95570b5d4 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -13615,6 +13615,9 @@ describe('Validators', () => { 'ECMJ4657496', 'TBJA7176445', 'AFFU5962593', + 'ABCU1234567HELLO', + 'JUNKJ1234567', + 'AB,1234567', ], }); }); @@ -13640,6 +13643,9 @@ describe('Validators', () => { 'ECMJ4657496', 'TBJA7176445', 'AFFU5962593', + 'ABCU1234567HELLO', + 'JUNKJ1234567', + 'AB,1234567', ], }); });