Closes issue #806: bad encodation switch in non-ASCII DataMatrix encodation (credit micjahn)

This commit is contained in:
Sean Owen 2017-05-31 10:49:41 +01:00
parent 11f5278aa7
commit 458923c3cd
5 changed files with 14 additions and 3 deletions

View file

@ -35,7 +35,8 @@ final class Base256Encoder implements Encoder {
int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode()); int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode());
if (newMode != getEncodingMode()) { if (newMode != getEncodingMode()) {
context.signalEncoderChange(newMode); // Return to ASCII encodation, which will actually handle latch to new mode
context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
break; break;
} }
} }

View file

@ -59,7 +59,8 @@ class C40Encoder implements Encoder {
if ((count % 3) == 0) { if ((count % 3) == 0) {
int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode()); int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode());
if (newMode != getEncodingMode()) { if (newMode != getEncodingMode()) {
context.signalEncoderChange(newMode); // Return to ASCII encodation, which will actually handle latch to new mode
context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
break; break;
} }
} }

View file

@ -39,6 +39,7 @@ final class EdifactEncoder implements Encoder {
int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode()); int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode());
if (newMode != getEncodingMode()) { if (newMode != getEncodingMode()) {
// Return to ASCII encodation, which will actually handle latch to new mode
context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION); context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
break; break;
} }

View file

@ -39,7 +39,8 @@ final class X12Encoder extends C40Encoder {
int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode()); int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode());
if (newMode != getEncodingMode()) { if (newMode != getEncodingMode()) {
context.signalEncoderChange(newMode); // Return to ASCII encodation, which will actually handle latch to new mode
context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
break; break;
} }
} }

View file

@ -349,6 +349,13 @@ public final class HighLevelEncodeTestCase extends Assert {
assertEquals("236 185 185 29 196 196 129 56", visualized); assertEquals("236 185 185 29 196 196 129 56", visualized);
} }
@Test
public void testEncodingWithStartAsX12AndLatchToEDIFACTInTheMiddle() {
String visualized = encodeHighLevel("*MEMANT-1F-MESTECH");
assertEquals("238 10 99 164 204 254 240 82 220 70 180 209 83 80 80 200", visualized);
}
@Ignore @Ignore
@Test @Test
public void testDataURL() { public void testDataURL() {