mojira.dev
MC-269160

Chat component JSON parser is too lenient in a few cases

The JSON parser used by components like custom_name, lore, written_book_content, as well as sign block entity data, is configured too lenient. This allows cursed chat components that wouldn't work in other places such as /tellraw

Relates to MC-265702

How to reproduce:

  1. Try running a command like this (notice the = and the missing quotes)

    /give @p stone[custom_name="{text=Test,'italic':0}"]
    /give @p stone[custom_name="{text=Test,'italic':0}"]
  2. ❌ Notice that the command is valid and you get an item named "Test" not italic

  3. Inspect the given item

    /data get entity @s SelectedItem
    /data get entity @s SelectedItem
  4. Notice that the actual (corrected) chat component is {"italic":false,"text":"Test"}

  5. Try to use the same chat component in /tellraw

    /tellraw @s {text=Test,'italic':0}
    /tellraw @s {text=Test,'italic':0}
  6. ✔ This command is invalid as expected and mentions that it is not using the lenient parser

Code analysis:
Commands such as /tellraw use ParserUtils.parseJson, which in turns sets jsonReader.setLenient(false).
In contrast, the custom_name data component uses ComponentSerialization.FLAT_CODEC, which uses com.google.gson.JsonParser.parseString() without setting lenient to false.

Comments 1

Thank you for your report!
After consideration, the issue is being closed as Won't Fix.

Please note that this is not the same as Working as Intended, as this bug report correctly describes behavior in the game that might not be the intended or desirable behavior, but it will not be fixed right now. Sometimes, this is because the issue reported is minor and/or impossible to change without large architectural changes to the code base.

Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki

Misode

(Unassigned)

Confirmed

(Unassigned)

24w10a

Retrieved