Stop dropping a leading "99" pair from Code128 barcodes (#251)#263
Open
gaoflow wants to merge 1 commit into
Open
Stop dropping a leading "99" pair from Code128 barcodes (#251)#263gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
In charset C the digit pair "99" encodes to the code number 99, which
is also the TO_C charset-switch marker. Code128._try_to_optimize folded
away a leading switch code, so a barcode whose data began with "99" had
that pair silently dropped: Code128("9912345678").encoded produced
[105, 12, 34, 56, 78], decoding to "12345678".
Restrict the START-code folding to a genuine START_C followed by a
switch to charset A or B, so the data value 99 is preserved while the
legitimate optimization (e.g. "Wikipedia" starting in charset B) still
applies. Fixes WhyNotHugo#251.
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.
Fixes #251.
A Code128 barcode whose data begins with
99silently loses that pair:Cause. In charset C the digit pair
"99"encodes to the code number 99, which is also theTO_Ccharset-switch marker (code128.TO = {101: START_A, 100: START_B, 99: START_C}).Code128._try_to_optimizefolds aSTART_Cimmediately followed by a switch code into a single start code, but it testedencoded[1] in code128.TOunconditionally, so a leading data pair of99was mistaken for a redundant switch and dropped.Fix. Restrict the fold to a genuine
START_Cfollowed by a switch to charset A or B (TO_A/TO_B). The data value99is preserved, and the legitimate optimization still applies — e.g."Wikipedia", which starts in charset B, still folds to a singleSTART_B.Tests (
tests/test_builds.py): leading"99"now round-trips; non-colliding leading pairs ("00…","12…") are unchanged; and the start-code folding optimization is asserted to still apply. Full suite: 50 passed.