Skip to content

Commit e31808d

Browse files
Fix exception where input is just an empty array or object
1 parent 6418374 commit e31808d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Editor/JSONObjectTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,18 @@ public void StaticHelpers() {
11561156
Assert.That(jsonObject.isNull, Is.True);
11571157
}
11581158

1159+
[Test]
1160+
public void EmptyObject() {
1161+
var emptyJsonObject = new JSONObject("{}");
1162+
Assert.That(emptyJsonObject.ToString(), Is.EqualTo("{}"));
1163+
}
1164+
1165+
[Test]
1166+
public void EmptyArray() {
1167+
var emptyJsonObject = new JSONObject("[]");
1168+
Assert.That(emptyJsonObject.ToString(), Is.EqualTo("[]"));
1169+
}
1170+
11591171
#if JSONOBJECT_POOLING
11601172
[OneTimeTearDown]
11611173
public void OneTimeTearDown() {

JSONObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ static bool BeginParse(string inputString, int offset, ref int endOffset, JSONOb
507507
if (endOffset >= stringLength)
508508
throw new ArgumentException("Cannot parse if end offset is greater than or equal to string length", "endOffset");
509509

510-
if (offset >= endOffset)
511-
throw new ArgumentException("Cannot parse if offset is greater than or equal to end offset", "offset");
510+
if (offset > endOffset)
511+
throw new ArgumentException("Cannot parse if offset is greater than end offset", "offset");
512512

513513
return true;
514514
}

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ void Test() {
159159

160160
## Change Log
161161

162+
### v2.1.3
163+
* Fix exception where input is just an empty array or object
164+
165+
### v2.1.2
166+
* Fix issue parsing json strings with whitespace after colon characters
167+
162168
### v2.1.1
163169
* Fix issue parsing nested arrays with multiple elements
164170
* Refactor MaxDepth tests

0 commit comments

Comments
 (0)