Better Questing

Better Questing

39M Downloads

JSON files use default encoding, may be incompatible across platforms

ryankoppenhaver opened this issue ยท 2 comments

commented

JsonIO.readFromFile and .writeToFile create FileReader and FileWriter objects to handle file I/O. These classes always use the default character encoding, which can vary based on the operating system or the user's general system settings.

This is mostly going to go unnoticed, as the most common encodings are compatible for common (basic ASCII) characters. One major exception is color formatting, which uses the "section sign" as an marker. This character may be encoded as A7 in "extended ASCII" encodings such as ISO8859-1, but is encoded as C2 A7 in UTF-8.

Here is one instance of this issue in the wild. I've also been able to reproduce it with the following steps:

  1. Run Minecraft with -Dfile.encoding=iso8859-1.
  2. Make some quests with color formatting, and quit.
  3. Open QuestDatabase.json with a hex editor. Note the A2 bytes.
  4. Re-run Minecraft with -Dfile.encoding=utf-8.
  5. Open the quest list, and see that the color escapes are mangled.
  6. Open QuestDatabase.json with a hex editor again. Note the A2 bytes have been replaced by EF BF BD (the "replacement character" sequence).

I'd suggest explicitly specifying UTF-8 for both input and output. Something like:

// FileReader fr = new FileReader(file);
InputStream is = new FileInputStream(file);
Reader r = new InputStreamReader(is, Charset.forName("UTF-8"));

...and similar for writing.

commented

yes, "The Ferret Business" is having the exact issue described here, Thank you ryankoppenhaver, for figuring it out.

commented

Just stating for future reference, this has been resolved in the BQ2 beta builds