Skip to content

Commit

Permalink
Merge pull request #615 from kenwa/master
Browse files Browse the repository at this point in the history
Fix encoding problem when CodedCharacterSet is set to "ESC - A"
  • Loading branch information
drewnoakes authored May 12, 2023
2 parents 93889ec + a5d515d commit e3235ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Source/com/drew/metadata/iptc/Iso2022Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class Iso2022Converter
private static final int DOT = 0xe280a2;
private static final byte LATIN_CAPITAL_G = 0x47;
private static final byte PERCENT_SIGN = 0x25;
private static final byte MINUS_SIGN = 0x2D;
private static final byte DOT_SIGN = 0x2E;
private static final byte ESC = 0x1B;

Expand All @@ -59,6 +60,9 @@ public static String convertISO2022CharsetToJavaCharset(@NotNull final byte[] by
if (bytes.length > 3 && bytes[0] == ESC && (bytes[3] & 0xFF | ((bytes[2] & 0xFF) << 8) | ((bytes[1] & 0xFF) << 16)) == DOT && bytes[4] == LATIN_CAPITAL_A)
return ISO_8859_1;

if (bytes.length > 2 && bytes[0] == ESC && bytes[1] == MINUS_SIGN && bytes[2] == LATIN_CAPITAL_A)
return ISO_8859_1;

return null;
}

Expand Down
1 change: 1 addition & 0 deletions Tests/com/drew/metadata/iptc/Iso2022ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public void testConvertISO2022CharsetToJavaCharset() throws Exception
assertEquals("UTF-8", Iso2022Converter.convertISO2022CharsetToJavaCharset(new byte[]{0x1B, 0x25, 0x47}));
assertEquals("ISO-8859-1", Iso2022Converter.convertISO2022CharsetToJavaCharset(new byte[]{0x1B, 0x2E, 0x41}));
assertEquals("ISO-8859-1", Iso2022Converter.convertISO2022CharsetToJavaCharset(new byte[]{0x1B, (byte)0xE2, (byte)0x80, (byte)0xA2, 0x41}));
assertEquals("ISO-8859-1", Iso2022Converter.convertISO2022CharsetToJavaCharset(new byte[]{0x1B, (byte)0x2D, (byte)0x41}));
}
}

0 comments on commit e3235ea

Please sign in to comment.