nbt-ts icon indicating copy to clipboard operation
nbt-ts copied to clipboard

SNBT parser fails to skip `\r` and `\t` chars.

Open Tnze opened this issue 7 months ago • 4 comments

The vanilla implement use java's Character.isWhitespace(), which includes , \t, \r, \n and so on.

https://github.com/Mojang/brigadier/blob/b92c420b2a292dd5c20f6adfafff5e21b9835c6d/src/main/java/com/mojang/brigadier/StringReader.java#L95

But in this library, only and \n are accepted.

https://github.com/janispritzkau/nbt-ts/blob/dd983053ac92e0baa688690d6100076cffda0857/src/snbt.ts#L87C66-L87C66

It cause errors when parsing such files.

See: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Character.html#isWhitespace(char)

Tnze avatar Nov 14 '23 16:11 Tnze

And what's the relationship of this package and @ironm00n/nbt-ts? Which one is actively maintaining and I should use?

Tnze avatar Nov 14 '23 16:11 Tnze

The SNBT implementation is most likely flawed in many other ways as well. It is not maintained. I'll add a note/warning to my unmaintained libraries. Thanks for the notice.

I'm not affiliated with the other npm package in any way.

janispritzkau avatar Nov 14 '23 18:11 janispritzkau

I remembered that I wrote a newer and more robust parser in this repository:

https://github.com/janispritzkau/deno-minecraft/blob/next/nbt/snbt.ts

janispritzkau avatar Nov 14 '23 18:11 janispritzkau

I remembered that I wrote a newer and more robust parser in this repository:

https://github.com/janispritzkau/deno-minecraft/blob/next/nbt/snbt.ts

Actually, I'm developing the formatting function for my snbt vscode extension. By simply parse and re-stringify.

Seems like your new implementation doesn't have "pretty" output option, which will be good to have.

Tnze avatar Nov 15 '23 01:11 Tnze