specify utf8 encoding

this should fix the following known bugs:
 - putting a U+2019 in the config causes it to become corrupted and
   ~double in size every launch
 - scripts become assembled incorrectly and the nbsp after your name in
   the chatbox becomes incorrect
 - the feed panel doesn't show emoji
This commit is contained in:
Max Weber
2020-08-24 09:41:54 -06:00
committed by Adam
parent ca2416a838
commit 431e09588b
32 changed files with 117 additions and 70 deletions

View File

@@ -33,6 +33,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Comparator;
@@ -103,7 +104,7 @@ public class FlatStorage implements Storage
for (Index idx : store.getIndexes())
{
String file = idx.getId() + EXTENSION;
try (BufferedReader br = new BufferedReader(new InputStreamReader(openReader(file))))
try (BufferedReader br = new BufferedReader(new InputStreamReader(openReader(file), StandardCharsets.UTF_8)))
{
int lineNo = 0;
Archive archive = null;
@@ -213,7 +214,7 @@ public class FlatStorage implements Storage
for (Index idx : store.getIndexes())
{
String file = idx.getId() + EXTENSION;
try (PrintStream br = new PrintStream(openWriter(file)))
try (PrintStream br = new PrintStream(openWriter(file), false, StandardCharsets.UTF_8.name()))
{
br.printf("protocol=%d\n", idx.getProtocol());
br.printf("revision=%d\n", idx.getRevision());

View File

@@ -26,8 +26,8 @@ package net.runelite.cache.io;
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public final class OutputStream extends java.io.OutputStream
{
@@ -181,16 +181,7 @@ public final class OutputStream extends java.io.OutputStream
public void writeString(String str)
{
byte[] b;
try
{
b = str.getBytes("ISO-8859-1");
}
catch (UnsupportedEncodingException ex)
{
throw new RuntimeException(ex);
}
writeBytes(b);
writeBytes(str.getBytes(StandardCharsets.ISO_8859_1));
writeByte(0);
}

View File

@@ -26,6 +26,8 @@ package net.runelite.cache.script.assembler;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import net.runelite.cache.definitions.ScriptDefinition;
import net.runelite.cache.script.Instructions;
import net.runelite.cache.script.assembler.rs2asmParser.ProgContext;
@@ -45,7 +47,7 @@ public class Assembler
public ScriptDefinition assemble(InputStream in) throws IOException
{
// Get our lexer
rs2asmLexer lexer = new rs2asmLexer(new ANTLRInputStream(in));
rs2asmLexer lexer = new rs2asmLexer(new ANTLRInputStream(new InputStreamReader(in, StandardCharsets.UTF_8)));
LexerErrorListener errorListener = new LexerErrorListener();
lexer.addErrorListener(errorListener);

View File

@@ -25,6 +25,7 @@
package net.runelite.cache.script.assembler;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import net.runelite.cache.definitions.ScriptDefinition;
import net.runelite.cache.script.Instructions;
import net.runelite.cache.script.disassembler.Disassembler;
@@ -76,7 +77,7 @@ public class AssemblerTest
in = AssemblerTest.class.getResourceAsStream(this.script);
Assert.assertNotNull(in);
String original = new String(IOUtils.toByteArray(in)).replaceAll("\r\n", "\n");
String original = new String(IOUtils.toByteArray(in), StandardCharsets.UTF_8).replaceAll("\r\n", "\n");
logger.info(original);
logger.info("-----------------------");

View File

@@ -27,6 +27,7 @@ package net.runelite.cache.script.disassembler;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import net.runelite.cache.IndexType;
import net.runelite.cache.StoreLocation;
import net.runelite.cache.definitions.ScriptDefinition;
@@ -78,7 +79,7 @@ public class DisassemblerTest
Disassembler disassembler = new Disassembler();
String out = disassembler.disassemble(script);
Files.write(out.getBytes(), outFile);
Files.write(out.getBytes(StandardCharsets.UTF_8), outFile);
++count;
}

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.cache.util;
import java.nio.charset.StandardCharsets;
import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
@@ -32,7 +33,7 @@ public class XteaTest
@Test
public void test()
{
byte[] data = "testtesttest1".getBytes();
byte[] data = "testtesttest1".getBytes(StandardCharsets.UTF_8);
int[] key = new int[]
{