mojira.dev
MC-265702

Text components in commands accept malformed JSON

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);
	// ...
}

Comments 0

No comments.

ErrorCraft

gegy

Confirmed

Platform

Important

Commands

23w40a

23w45a

Retrieved