Fix encoding for appended strings

If a packet is constructed using the expression form, PacketStringUtils will encode properly the string like this:
String latin = new String(actualString.toString().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);

This does not happen if the packet is constructed using the Object... constructor,
and packets like this:

 new HPacket(10, 2, 100000, "Dragón de Fuego Azul", 3).toExpression();

 will show � instead of ó.
 Whereas:

 new HPacket("{l}{h:10}{i:2}{i:100000}{s:\"Dragón de Fuego Azul\"}{i:3}").toExpression();

 would display the string correctly.
This commit is contained in:
Eduardo Alonso 2021-01-07 13:27:10 +01:00
parent 89da267a33
commit 56cc99e0e6

View File

@ -491,6 +491,7 @@ public class HPacket implements StringifyAble {
return this;
}
public HPacket appendString(String s) {
s = new String(s.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
return appendString(s, StandardCharsets.ISO_8859_1);
}