Skip to content

Parsing empty multiline dictionary causes exception #55

Description

@Zdreni

Simple json causes exception "ArgumentOutOfRangeException: Length cannot be less than zero.":

{
  "instances": {
  }
}

Claude suggest following patch:

@@ -940,11 +940,13 @@ namespace Defective.JSON {
 		}
 
 		static void ParseFinalObjectIfNeeded(string inputString, JSONObject container, int startOffset, int lastValidOffset) {
-			if (IsClosingCharacter(inputString[lastValidOffset]))
+			// lastValidOffset only advances past non-whitespace characters, so if it still points at
+			// whitespace, nothing but whitespace has been seen since the last comma/colon/opening bracket
+			// and there's no pending value to parse (e.g. an object/array containing only whitespace).
+			if (IsClosingCharacter(inputString[lastValidOffset]) || Array.IndexOf(Whitespace, inputString[lastValidOffset]) > -1)
 				return;
 
 			var child = Create();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions