Skip to content

Fix switch fall-through breaking 46 application identifiers, add full AI coverage and CI - #6

Merged
MaximBelov merged 7 commits into
masterfrom
fix/switch-fallthrough
Aug 13, 2026
Merged

MaximBelov merged 7 commits into
masterfrom
fix/switch-fallthrough

Conversation

@MaximBelov

Copy link
Copy Markdown
Owner

Includes @matevzv's #5, with a second fall-through of the same shape that @Duskfen spotted while reviewing it, plus the test that would have caught both.

The bug

The parser is one large nested switch. In two places an inner switch closed without a break, so execution ran on into the enclosing default. Parsing all 193 identifiers the library claims to support, 46 of them are broken on the published 1.0.7:

Identifiers Behaviour on 1.0.7
4300–4333 (31 codes: ship-to and return-to addresses, delivery dates, temperature limits) throws invalid AI after '4'
710–715 (national healthcare reimbursement numbers: PZN, CIP, CN, DRN, PT, NDC) throws invalid AI after '70'
7010 parsed, then silently relabelled as 7011
7020–7023, 7040, 7240–7242 come back with ai: undefined

The 7010 case is the unpleasant one: it returns successfully with the wrong identifier and the wrong data title, so a caller has no way to tell.

#5 fixes the 70xx family. The 43xx family needed one more break, which is @Duskfen's review comment on that PR. With both, all 193 parse correctly.

The test

spec/ApplicationIdentifiersSpec.js parses every supported identifier on its own and checks it comes back as exactly one element under its own AI. That catches all four failure modes above — throw, undefined, wrong AI, and extra elements — and it fails 46 specs without the two fixes.

The existing suite covers seven codes, none in the affected families, which is why this went unnoticed across several releases.

Toolchain

The suite could not actually run, so this had to come with it:

  • grunt-contrib-jasmine drives PhantomJS, which no longer starts. npm test did not fail, it hung indefinitely.
  • grunt-contrib-uglify is UglifyJS2, which cannot parse the ES6 const in src/BarcodeParser.js, so the dist build failed outright.

That left jshint as the only working grunt task, so grunt is replaced by jasmine, jshint and terser called directly from npm scripts. npm test now runs in ~10ms, and the dependency tree drops from 390 packages to 85. Specs require the parser instead of relying on a browser global.

CI and publishing

  • ci.yml runs lint, specs and build on every push and pull request, on Node 24.
  • publish.yaml publishes from master via Trusted Publishing (OIDC, no NPM_TOKEN), and only when the version in package.json is not already on the registry — so a push that does not change the version is a green no-op rather than a 403.

Version bumped to 1.0.8 so the fix actually ships. The Trusted Publisher for gs1-barcode-parser-mod has to be configured in the npmjs.com UI before this merges — it is a manual, 2FA-gated step, and the first publish run fails without it.

Also

  • README gets a fork-reason section, and the note about a checked-in minified build is replaced — dist is built by npm run build and is not in the repository.

Related

matevzv and others added 7 commits August 13, 2026 03:57
The switch on the third digit of a 43xx identifier closed without a break, so
every 4300-4333 code ran on into the enclosing default and threw "17" after it
had already been parsed correctly.
Two of the three grunt tasks had stopped working. grunt-contrib-jasmine runs the
suite through PhantomJS, which no longer starts, so "npm test" hung instead of
running; grunt-contrib-uglify is UglifyJS2, which cannot parse the ES6 const the
source has used since it was modernised, so the dist build failed outright. That
left jshint as the only task still doing anything.

The specs now require the parser rather than picking it up as a browser global,
which is what let PhantomJS in through the front door in the first place.
The parser is one large nested switch, so a missing break or a stray brace makes
an identifier throw, come back as undefined, or silently parse as its neighbour.
None of that was visible to a suite covering seven codes: against the previous
commits' fixes this spec fails 46 of 193 identifiers, and every one of those had
been broken on a published release.
Adds the fork-reason section, replaces the stale note about a checked-in minified
build, and writes down what the spec suite is actually guarding against.
Publishes only when the version in package.json is not already on the registry,
so an ordinary push to master is a green no-op rather than a failure on npm's
403 for an existing version.
@MaximBelov
MaximBelov merged commit f619dbb into master Aug 13, 2026
1 check passed
@MaximBelov MaximBelov mentioned this pull request Aug 13, 2026
@MaximBelov
MaximBelov deleted the fix/switch-fallthrough branch August 13, 2026 05:47
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.

2 participants