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

NBT.stringify does not escape things correctly when used in JSON (as opposed to commands) #131

Open
GrantGryczan opened this issue Dec 18, 2021 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@GrantGryczan
Copy link
Contributor

GrantGryczan commented Dec 18, 2021

NBT.stringify({ test: '\n' }) should output "{test:'\n'}" when used in a JSON file, not "{test:'\\n'}". This input impossible to specify in commands validly though.

Minimal reproduction code:

LootTable('test:book', {
    type: 'command',
    pools: [{
        rolls: 1,
        entries: [{
            type: 'minecraft:item',
            name: 'minecraft:writable_book',
            functions: [{
                function: 'set_nbt',
                tag: NBT.stringify({
                    pages: ['line 1\nline 2']
                })
            }]
        }],
        bonus_rolls: 0
    }]
});

Minecraft does not recognize this NBT as valid. Entering /loot give @s loot test:book will not work. Opening the outputted loot table file shows this error:

image

And Minecraft logs this error:

image

@Command-Master
Copy link

I'm fairly sure you actually can't have newlines in NBT text. Are you sure there is any valid output?

@GrantGryczan
Copy link
Contributor Author

GrantGryczan commented Dec 19, 2021

Yes you can, and removing the double slashes fixes it.

@TheMrZZ
Copy link
Collaborator

TheMrZZ commented Dec 19, 2021

Can you show me a detailed example? Minecraft does not seem to accept \n, while \\n is accepted.

This works:
image

This doesn't:
image

@GrantGryczan
Copy link
Contributor Author

GrantGryczan commented Dec 19, 2021

This NBT is not in a Minecraft command. It's in a string in a JSON file.

I realize this issue is more complicated that I thought, because it seems escaping needs to be done differently between NBT in a JSON string and NBT in a command.

Edit: Never mind, \n isn't even valid in NBT for a command, escaped or not. It's not a valid escape sequence.

@TheMrZZ TheMrZZ added the invalid This doesn't seem right label Dec 19, 2021
@GrantGryczan GrantGryczan changed the title NBT.stringify does not process \n (and possibly other escaped characters) correctly NBT.stringify does not escape things correctly when used in JSON (as opposed to commands) Dec 19, 2021
@TheMrZZ TheMrZZ added bug Something isn't working help wanted Extra attention is needed and removed invalid This doesn't seem right labels Dec 19, 2021
@MulverineX MulverineX added this to the 0.14 milestone Jan 30, 2023
@MulverineX MulverineX modified the milestones: 0.14, Future Release Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants