Mojira Archive
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}"]
    
  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
    
  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}
    
  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.

Won't Fix

[Helper] Misode

2024-03-07, 02:45 AM

2024-03-07, 08:08 AM

2024-03-07, 08:08 AM

0

2

Confirmed

(Unassigned)

24w10a

-