ComunidadAylas / PackSquash

📦 Minecraft: Java Edition resource and data pack optimizer which aims to achieve the best possible compression, performance and protection, improving pack distribution, storage and in-game load times.
https://packsquash.aylas.org
GNU Affero General Public License v3.0
591 stars 24 forks source link

Ignore control characters for JSON format. #36

Closed Aiamded closed 3 years ago

Aiamded commented 3 years ago

Describe the bug JSON error: control character (\u0000-\u001F) found while parsing a string at line.

AlexTMjugador commented 3 years ago

Thanks for trying out PackSquash and the report!

Unfortunately, though, due to the lack of any additional context, I can't imagine exactly how this error can signal an issue with PackSquash. I've looked at the official JSON specification, and indeed control characters can't legally appear within a string, as shown by this fancy diagram available at that website. So I'd say that PackSquash behavior is correct here.

JSON string grammar diagram (click to show) ![JSON string grammar diagram](https://www.json.org/img/string.png)

Minecraft might be able to parse that JSON string as expected, but that would only be because it uses a different parser that is more lenient. If for some reason Minecraft decides to change its parser such non-standard strings may end up breaking. Moreover, adhering to the JSON specification also helps with interoperability, because it allows you to use more programs with your JSON file, which is very useful for advanced use cases. Therefore, PackSquash behavior, apart from being correct according to the standard, is also helpful in the long run and if you decide to get creative, even if right now it might look like an inconvenience. (The only exception to this is that PackSquash supports comments too, but they are easy to strip out, it is easy to tell apart whether you are using this extension or not, and they are a very useful feature for human comprehension, especially in packs that live in a repository and/or are authored by several people. I also plan to add an option to even disallow comments, for maximum interoperability.)

If you need to put a control character in a JSON string, the standards-conformant way to do so is to escape it. For example, if you want to insert a newline character (line break, LF, ASCII code 0x0A), you can either write \n or \u000A, much like it is done in programming languages. If you have a bunch of control characters you need to replace, a regular expression might come in handy.

Please share if anything I've said helps you resolve your issue, or state any other interesting context about the issue, especially if it may prove that PackSquash does something wrong, or that it could do something better.

Aiamded commented 3 years ago

Thanks for the clarification. Though if you don't mind helping me out what can I do with this error "! Pack processing error: An error occurred while processing a pack file".

AlexTMjugador commented 3 years ago

That error just appears at the end of the PackSquash output if another error happened while processing a pack file, to remind you that something went wrong. If you fix any previously shown pack file processing error, like the one you reported in this issue, it will go away.

Aiamded commented 3 years ago

Oh glad to know, Thank you very much!