From 56cc99e0e665d3a7efc722dbbbd238fa0e475419 Mon Sep 17 00:00:00 2001 From: Eduardo Alonso Date: Thu, 7 Jan 2021 13:27:10 +0100 Subject: [PATCH] Fix encoding for appended strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- G-Earth/src/main/java/gearth/protocol/HPacket.java | 1 + 1 file changed, 1 insertion(+) diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index c1cfb94..4b2bf1c 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -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); }