Fix decoding of FNC1 in AztecCode. (#1441)

* Fix decoding of FNC1 in AztecCode. Flush buffer to make sure FNC1 is output in the correct
position in the stream.

* Simplify. Flush buffers outside switch, as it happens for all non-error cases anyway.
This commit is contained in:
Anders Hammarquist 2021-09-28 22:28:07 +02:00 committed by GitHub
parent 83650ce341
commit fc50fca12f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View file

@ -153,6 +153,13 @@ public final class Decoder {
}
int n = readCode(correctedBits, index, 3);
index += 3;
// flush bytes, FLG changes state
try {
result.append(decodedBytes.toString(encoding.name()));
} catch (UnsupportedEncodingException uee) {
throw new IllegalStateException(uee);
}
decodedBytes.reset();
switch (n) {
case 0:
result.append((char) 29); // translate FNC1 as ASCII 29
@ -160,15 +167,6 @@ public final class Decoder {
case 7:
throw FormatException.getFormatInstance(); // FLG(7) is reserved and illegal
default:
// flush bytes before changing character set
try {
result.append(decodedBytes.toString(encoding.name()));
} catch (UnsupportedEncodingException uee) {
// can't happen
throw new IllegalStateException(uee);
}
decodedBytes.reset();
// ECI is decimal integer encoded as 1-6 codes in DIGIT mode
int eci = 0;
if (endIndex - index < 4 * n) {

View file

@ -50,6 +50,11 @@ public final class DecoderTest extends Assert {
testHighLevelDecodeString("±Ça",
// B/S 1 0xb1 P/S FLG(n) 2 '2' '6' B/S 2 0xc3 0x87 L/L 'a'
"XXXXX ....X X.XX...X ..... ..... .X. .X.. X... XXXXX ...X. XX....XX X....XXX XXX.. ...X.");
// GS1 data
testHighLevelDecodeString("101233742",
// P/S FLG(n) 0 D/L 1 0 1 2 3 P/S FLG(n) 0 3 7 4 2
"..... ..... ... XXXX. ..XX ..X. ..XX .X.. .X.X .... ..... ... .X.X X..X .XX. .X..");
}
private static void testHighLevelDecodeString(String expectedString, String b) throws FormatException {