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

Text components in commands accept malformed JSON

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 23w45a
    • 23w40a
    • None
    • Confirmed
    • Commands
    • Important
    • Platform

      Step(s) to reproduce:

      1. Enter the following command in chat:
        /tellraw @a {text: hello}
        

      Result: It displays hello in chat.
      Expected result: It errors out, stating it's malformed JSON.

      Code analysis:
      The net.minecraft.network.chat.Component.Serializer::fromJson(com.mojang.brigadier.StringReader) method now calls com.google.gson.JsonParser::parseReader, and while it calls setLenient(false) beforehand, the JsonParser::parseReader method sets it back to true, which causes it to accept malformed JSON, such as unquoted strings.

      // net.minecraft.network.chat.Component.Serializer
      public static MutableComponent fromJson(com.mojang.brigadier.StringReader stringReader) {
      	try {
      		// ...
      		jsonReader.setLenient(false);
      		JsonElement jsonElement = JsonParser.parseReader(jsonReader);
      		// ...
      	} // ...
      }
      
      // com.google.gson.JsonParser
      public static JsonElement parseReader(JsonReader reader) throws JsonIOException, JsonSyntaxException {
      	// ...
      	reader.setLenient(true);
      	// ...
      }
      

            gegy1000 [Mojang] Gegy
            ErrorCraft ErrorCraft
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: