python-barcode icon indicating copy to clipboard operation
python-barcode copied to clipboard

Code128 issue, codes starting with 99 will have that stripped from finished barcode

Open rejjen opened this issue 6 months ago • 1 comments

When generating Code128 barcode for code "999999" for example

The resulting svg will not include the first pair of nines.

Below are snippets for testing, which may or may not be optimal for illustrating the problem.

tests/test_builds.py

def test_code128_builds() -> None:
    gen_000000 = get_barcode("code128", "000000")
    code_000000 = gen_000000.build()
    gen_999999 = get_barcode("code128", "999999")
    code_999999 = gen_999999.build()

    assert len(code_000000[0]) == len(code_999999[0])

tests/test_init.py, to generate a svg

def test_generate_99999() -> None:
    with open(os.path.join(TESTPATH, "generate_999999.svg"), "wb") as f:
        barcode.generate("code128", "999999", output=f, writer=SVGWriter())

This is as far as I can tell behavior that is related to charset C for Code128, and may possibly be intentional. But it feels very random.

Looks like this where this stripping happens. https://github.com/WhyNotHugo/python-barcode/blob/85acbda24151d5ce155b3299077a87b25fcd2cc2/barcode/codex.py#L269C5-L272C23

rejjen avatar Sep 27 '25 19:09 rejjen

Same experience here with v 0.16.1

Does work with 0.15.1 though...

maheini avatar Oct 11 '25 21:10 maheini