Skip to content

textutils.unserialiseJSON(s, {nbt_style=true}) does not support all allowed characters for key names #2277

@hooded-person

Description

@hooded-person

Minecraft Version

1.21.1

Version

1.116.0

Details

On CraftOs 1.9
When using textutils.unserialiseJSON(s, {nbt_style=true}) not all valid nbt strings are parsed as valid, some causing errors in textutils.lua instead of returning nil and an error message.
Examples will show the return values of textutils.unserialiseJSON(s, {nbt_style=true}) where s is the value specified in the example.

According to the wiki valid characters for unquoted keys are 0-9, A-Z, a-z, _, -, ., and + however not all of these are parsed correctly:

Completely unsupported

-, . and + are not parsed at all and will cause nil and an error message to be returns
Examples
s = '{entity-name:"james"}' returns nil and Malformed JSON at position 8: Unexpected "-", expected ':'.
s = '{silentlib.SpawnItemsGiven: {}}' returns nil and Malformed JSON at position 11: Unexpected ".", expected ':'.
s = '{bank+wallet: 139}' returns nil and Malformed JSON at position 6: Unexpected "+", expected ':'.

Unsupported at beginning of key

0-9, _, -, ., and + cause errors within textutils.lua when at the beginning of the key. All of the following examples cause the following error:

...rom/apis/textutils.lua:620: attempt to preform arithmetic on local 'last' (a nil value)

(Providing no key also gives this error instead of returning nil and an error message)
Examples
s = '{0of10: true}'
s = '{_broken: 5}'
s = '{-s: true}'
s = '{.james: []}'
s = '{+majo: true}'

Note

All example nbt has been checked and is valid when used in minecraft.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CraftOSThis affects CraftOS, or any other Lua portions of the mod.bugA problem or unexpected behaviour with the mod.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions