allthingssecurity opened a new pull request, #27344: URL: https://github.com/apache/camel/pull/27344
# Description [CAMEL-25303](https://issues.apache.org/jira/browse/CAMEL-25303) Two problems with the text encoding of `BarcodeDataFormat`: 1. No `CHARACTER_SET` hint is given to ZXing, which then writes the text in ISO-8859-1 and replaces everything else by `?`: `日本語のテキスト` comes back as `????????`, `Привет, мир` as `??????, ???` (QR code, Aztec), and PDF417 fails with `Non-encodable character detected`. The documentation says the default encoding is UTF-8. 2. Since CAMEL-22354 (4.15.0, so 4.18.x and main) the hints are computed in `doStart()`, which clears the hint maps, so hints added with `addToHintMap` before the route starts (the documented way to configure ZXing) are dropped; a `CHARACTER_SET` hint cannot even be used to work around 1. This change: - encodes a text that ISO-8859-1 cannot represent as UTF-8 when no `CHARACTER_SET` hint is given (ZXing writes an ECI); a text that ISO-8859-1 can represent is encoded exactly as before, so existing barcodes do not change (QR code, Aztec and PDF417 use the character set; ZXing's Data Matrix writer only with `DATA_MATRIX_COMPACT`, the linear formats never); - keeps the user's hints apart and applies them on top of the default hints whenever these are computed (CAMEL-7870's re-optimization still drops the defaults of another format, not the user's hints); - corrects the default encoding in the documentation (and the catalog copy). Tests: new `BarcodeDataFormatCharsetTest`: Japanese and Cyrillic in a QR code, Cyrillic in Aztec and PDF417, hints added before start, a `CHARACTER_SET=UTF-8` hint added before start is used (byte segment of the UTF-8 bytes); control: ASCII and ISO-8859-1 text. Without the change 6 fail, the control passes; with it the module passes (33 tests). Found with a Lean 4 model of the text encoding and the hint maps: "unmarshal(marshal(text)) = text" fails for every text with a character outside ISO-8859-1 and is proved for the fix for every Unicode text (with today's bytes for ISO-8859-1 text); "a hint added before start is in force after start" fails today and holds with the fix. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested the affected module, including the formatter and import-sort plugins. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
