Read Json stream as UTF-8 Do not (implicitly) rely on Charset.defaultCharset(). RFC 8259 specifies UTF-8 unless in a closed system. Older RFC 7159 and RFC 4627 allowed UTF-8, UTF-16, UTF-32, big or little endian, with or without BOM. Change-Id: I33ddfacccc97f81d9eeaf444f734c469028c8214 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
diff --git a/org.eclipse.tips.json/src/org/eclipse/tips/json/JsonTipProvider.java b/org.eclipse.tips.json/src/org/eclipse/tips/json/JsonTipProvider.java index 95d8fc7..ec6312c 100644 --- a/org.eclipse.tips.json/src/org/eclipse/tips/json/JsonTipProvider.java +++ b/org.eclipse.tips.json/src/org/eclipse/tips/json/JsonTipProvider.java
@@ -18,6 +18,7 @@ import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.text.ParseException; import java.util.ArrayList; @@ -105,7 +106,10 @@ } private JsonObject loadJsonObject() throws IOException { - try (InputStream stream = fJsonUrl.openStream(); InputStreamReader reader = new InputStreamReader(stream)) { + // RFC 8259: https://tools.ietf.org/html/rfc8259#section-8.1 + // Json MUST be encoded as UTF-8, unless in a closed system. + try (InputStream stream = fJsonUrl.openStream(); + InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { Object result = JsonParser.parseReader(reader); if (result instanceof JsonObject) { return (JsonObject) result;