Skip to content

fix: translate Codabar start/end characters when ReturnCodabarStartEnd is set - #113

Merged
hschimke merged 1 commit into
rxing-core:mainfrom
porxyz:fix/codabar-return-start-end
Oct 24, 2026
Merged

hschimke merged 1 commit into
rxing-core:mainfrom
porxyz:fix/codabar-return-start-end

Conversation

@porxyz

@porxyz porxyz commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Problem

With DecodeHintValue::ReturnCodabarStartEnd(true), CodaBarReader returns internal alphabet-table indices instead of characters. Default decoding, which strips the start and end characters, is correct.

To reproduce:

use rxing::oned::{CodaBarReader, CodaBarWriter, OneDReader};
use rxing::{BarcodeFormat, DecodeHintValue, DecodeHints, Writer};

let matrix = CodaBarWriter.encode("A1234B", &BarcodeFormat::CODABAR, 0, 0)?;
let hints = DecodeHints::default().with(DecodeHintValue::ReturnCodabarStartEnd(true));
let result = CodaBarReader::default().decode_row(0, &matrix.getRow(0), &hints)?;
println!("{:?}", result.getText());
// main:        "\u{10}\u{1}\u{2}\u{3}\u{4}\u{11}"
// this branch: "A1234B"

Cause

CodaBarReader::decode_row collects alphabet indices in decodeRowRXingResult, then translates them into characters in a local copy, cached_drrr. That copy is written back only in the branch that strips the start and end characters. With the hint set, the untranslated indices become the result text.

ZXing translates decodeRowResult in place, so this is specific to the Rust port.

Fix

Store the translated characters in both cases: the whole string when the hint is set, the inner characters otherwise.

Test

This PR adds testDecodeWithStartEnd to CodaBarWriterTestCase, behind feature = "decoders". It encodes A1234B and C-$:/.+D and decodes each one with and without the hint.

Without the fix, it fails:

assertion `left == right` failed
  left: "A1234B"
 right: "\u{10}\u{1}\u{2}\u{3}\u{4}\u{11}"

With the fix, it passes.

I also decoded all 16 start/stop pairs (A–D × A–D) from a separate encoder. With the hint, main returns the right text for 0 of 16 and this branch for 16 of 16. Without the hint, both return the right text for 16 of 16.

Both CI test steps, cargo test --workspace --release and the same with --no-default-features, pass on this branch.


I found this while using rxing to check a barcode encoder by decoding its output. The change and this description were prepared with AI assistance (Claude, via Claude Code). I reviewed the change and the test results before opening this PR. It is contributed under the Apache License 2.0.

🤖 Generated with Claude Code

…d is set

CodaBarReader translated alphabet indices into a copy and stored the copy
only when the start/end characters were stripped. With
ReturnCodabarStartEnd the result text was the raw indices, e.g.
"\x10\x01\x02\x03\x04\x11" for A1234B. ZXing translates in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hschimke
hschimke merged commit d759f1a into rxing-core:main Oct 24, 2026
1 check passed
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