Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding problem when CodedCharacterSet is set to "ESC - A" #615

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}));
}
}