mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fix Json.ParseJson crash on empty/null input
ParseJson now returns null for null, empty, or whitespace-only input instead of throwing JsonReaderException. This matches the behavior of the old hand-rolled parser and is needed because MC protocol packets may contain empty strings where JSON text is expected (e.g. empty chat messages in DeathCombatEvent packets). Discovered during end-to-end testing against a Minecraft 1.21.11 protocol server. Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> Agent-Logs-Url: https://github.com/milutinke/Minecraft-Console-Client/sessions/34df723e-4a63-45a0-a942-e119d81a575b
This commit is contained in:
parent
64ccdcb39b
commit
d2c1cbf2a5
1 changed files with 3 additions and 1 deletions
|
|
@ -16,8 +16,10 @@ public static class Json
|
|||
|
||||
/// <summary>
|
||||
/// Parse a JSON string into a mutable <see cref="JsonNode"/> DOM.
|
||||
/// Returns null for null, empty, or whitespace-only input.
|
||||
/// </summary>
|
||||
public static JsonNode? ParseJson(string json) => JsonNode.Parse(json);
|
||||
public static JsonNode? ParseJson(string? json) =>
|
||||
string.IsNullOrWhiteSpace(json) ? null : JsonNode.Parse(json);
|
||||
|
||||
/// <summary>
|
||||
/// Escape a string for embedding inside a JSON string literal.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue