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

SNBT Parser cannot parse negative numbers in IntArrays #32

Open
Fisch37 opened this issue May 11, 2024 · 3 comments
Open

SNBT Parser cannot parse negative numbers in IntArrays #32

Fisch37 opened this issue May 11, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Fisch37
Copy link

Fisch37 commented May 11, 2024

Title...

Attempting to parse an integer array fails with a SyntaxError if the array contains a negative number.
This effectively means that any SNBT containing a UUID fails as those are length 4 Integer Arrays and UUID format guarantees a negative number here.

A simple check to confirm:

StringNbt.Parse("{uuid:[I; 0, 0, 0, -1]}");

throws

System.Data.SyntaxErrorException: 'Syntax error at index 19: Invalid character '-' in integer array.'
@Fisch37
Copy link
Author

Fisch37 commented May 11, 2024

Proposed Fix

The fix for this is trivial. Some light testing shows the following fix works fine:

Alter line 352 of SharpNBT.SNBT.StringNbt from

if (char.IsNumber(c) || c == ',')

to

if (char.IsNumber(c) || c == '-' || c == ',')

@ForeverZer0
Copy link
Owner

Well, that is an embarrassing oversight on my part, no clue how I let that happen....

I don't have the code on my current machine to test with, but the fix would likely also require and additional check to ensure the - is the first character, and not just anywhere within the string (e.g. -123 is valid, but 1-2-3- is not). Either way, it will be a trivial fix to implement, thank you for taking the time to report.

@ForeverZer0 ForeverZer0 added the bug Something isn't working label May 12, 2024
@Fisch37
Copy link
Author

Fisch37 commented May 13, 2024

the fix would likely also require and additional check to ensure the - is the first character, and not just anywhere within the string

That's true! Good catch! Thanks to you for taking the time to develop this thing! (Like seriously, I think this is the only SNBT parser library for C#)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants