mirror of
https://github.com/revanced/Apktool.git
synced 2025-06-12 13:17:43 +02:00
fix: when decoding with UTF-8 fails, create a new buffer for the retry with CESU-8.
If the decoding fails and there are UTF-8 decodable bytes before the bytes that couldn't be decoded, then the read index of the original buffer is incremented and those bytes will be missing from the decode result. Now we create a new buffer and the decoding will start at the original start offset. issue #2546
This commit is contained in:
@ -52,6 +52,20 @@ public class StringBlockWithSurrogatePairInUtf8Test {
|
||||
// See: https://github.com/iBotPeaches/Apktool/issues/2299
|
||||
final String actual = new StringBlock(new byte[] { (byte) 0xED, (byte) 0xA0, (byte) 0xBD, (byte) 0xED, (byte) 0xB4, (byte) 0x86}, true).decodeString(0, 6);
|
||||
assertEquals("Incorrect decoding", "\uD83D\uDD06", actual);
|
||||
|
||||
// See: https://github.com/iBotPeaches/Apktool/issues/2546
|
||||
final byte[] bytesWithCharactersBeforeSurrogatePair = {'G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g', '!', ' ',
|
||||
(byte) 0xED, (byte) 0xA0, (byte) 0xBD, (byte) 0xED, (byte) 0xB1, (byte) 0x8B,
|
||||
' ', 'S', 'u', 'n', ' ',
|
||||
(byte) 0xED, (byte) 0xA0, (byte) 0xBD, (byte) 0xED, (byte) 0xBC, (byte) 0x9E
|
||||
};
|
||||
final String actual2 = new StringBlock(bytesWithCharactersBeforeSurrogatePair, true).decodeString(0, 31);
|
||||
|
||||
// D83D -> ED 0xA0 0xBD
|
||||
// DC4B -> 0xED 0xB1 0x8B
|
||||
// DF1E -> 0xED 0xBC 0x9E
|
||||
assertEquals("Incorrect decoding when there are valid characters before the surrogate pair",
|
||||
"Good morning! \uD83D\uDC4B Sun \uD83C\uDF1E", actual2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user