Repository navigation
Fix switch fall-through breaking 46 application identifiers, add full AI coverage and CI - #6
Merged
Merged
Conversation
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.
Closed
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.
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 innerswitchclosed without abreak, so execution ran on into the enclosingdefault. Parsing all 193 identifiers the library claims to support, 46 of them are broken on the published 1.0.7:4300–4333(31 codes: ship-to and return-to addresses, delivery dates, temperature limits)invalid AI after '4'710–715(national healthcare reimbursement numbers: PZN, CIP, CN, DRN, PT, NDC)invalid AI after '70'701070117020–7023,7040,7240–7242ai: undefinedThe
7010case 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
70xxfamily. The43xxfamily needed one morebreak, which is @Duskfen's review comment on that PR. With both, all 193 parse correctly.The test
spec/ApplicationIdentifiersSpec.jsparses 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-jasminedrives PhantomJS, which no longer starts.npm testdid not fail, it hung indefinitely.grunt-contrib-uglifyis UglifyJS2, which cannot parse the ES6constinsrc/BarcodeParser.js, so thedistbuild failed outright.That left
jshintas the only working grunt task, so grunt is replaced byjasmine,jshintandtersercalled directly from npm scripts.npm testnow runs in ~10ms, and the dependency tree drops from 390 packages to 85. Specsrequirethe parser instead of relying on a browser global.CI and publishing
ci.ymlruns lint, specs and build on every push and pull request, on Node 24.publish.yamlpublishes frommastervia Trusted Publishing (OIDC, noNPM_TOKEN), and only when the version inpackage.jsonis 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.8so the fix actually ships. The Trusted Publisher forgs1-barcode-parser-modhas 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
distis built bynpm run buildand is not in the repository.Related
43xxbreakand test coverage. Credit to @matevzv for finding it and @Duskfen for the second one.