Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON files use default encoding, may be incompatible across platforms #68

Closed
ryankoppenhaver opened this issue Sep 7, 2016 · 2 comments

Comments

@ryankoppenhaver
Copy link

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.

@TheBlueTroll
Copy link

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

@Funwayguy
Copy link
Owner

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

ALongStringOfNumbers pushed a commit to ALongStringOfNumbers/BetterQuesting that referenced this issue Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants