Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-269160

Chat component JSON parser is too lenient in a few cases

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • None
    • 24w10a
    • None
    • Confirmed
    • (Unassigned)

      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.

            Unassigned Unassigned
            Misoloo [Helper] Misode
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: