From 80b08dbe0cc63b53950bf89f9d73561245fee28a Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 14 Sep 2019 21:17:18 -0500 Subject: [PATCH] Fix exception parsing empty JSON arrays. --- smx-config/SMXJSON.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/smx-config/SMXJSON.cs b/smx-config/SMXJSON.cs index 51ede86..f9cb2b2 100644 --- a/smx-config/SMXJSON.cs +++ b/smx-config/SMXJSON.cs @@ -360,22 +360,25 @@ namespace SMXJSON List result = new List(); while(true) { - Object value = ParseJSONValue(reader); - result.Add(value); - SkipWhitespace(reader); - int nextCharacter = reader.Read(); - switch(nextCharacter) + if(reader.Peek() == ']') { - case ']': + reader.Read(); return result; - case ',': - continue; - case -1: - throw new ParseError(reader, "Unexpected EOF reading array"); - default: - throw new ParseError(reader, "Unexpected token " + nextCharacter + " reading array"); } + + if(result.Count > 0) + { + int comma = reader.Read(); + if(comma == -1) + throw new ParseError(reader, "Unexpected EOF reading array"); + if(comma != ',') + throw new ParseError(reader, "Expected ',', got " + comma + " reading array"); + SkipWhitespace(reader); + } + + Object value = ParseJSONValue(reader); + result.Add(value); } } static private Dictionary ReadJSONDictionary(StringReader reader)