Skip to content

Commit 72aa518

Browse files
committed
Allow trailing comma in arrays if dropped null placeholders are not allowed
1 parent f0e7848 commit 72aa518

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

src/lib_json/json_reader.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,16 @@ bool Reader::readArray(Token& token) {
502502
Value init(arrayValue);
503503
currentValue().swapPayload(init);
504504
currentValue().setOffsetStart(token.start_ - begin_);
505-
skipSpaces();
506-
if (current_ != end_ && *current_ == ']') // empty array
507-
{
508-
Token endArray;
509-
readToken(endArray);
510-
return true;
511-
}
512505
int index = 0;
513506
for (;;) {
507+
skipSpaces();
508+
if (current_ != end_ && *current_ == ']' && (index == 0 || (features_.allowTrailingCommas_ && !features_.allowDroppedNullPlaceholders_))) // empty array or trailing comma
509+
{
510+
Token endArray;
511+
readToken(endArray);
512+
return true;
513+
}
514+
514515
Value& value = currentValue()[index++];
515516
nodes_.push(&value);
516517
bool ok = readValue();
@@ -1477,15 +1478,15 @@ bool OurReader::readArray(Token& token) {
14771478
Value init(arrayValue);
14781479
currentValue().swapPayload(init);
14791480
currentValue().setOffsetStart(token.start_ - begin_);
1480-
skipSpaces();
1481-
if (current_ != end_ && *current_ == ']') // empty array
1482-
{
1483-
Token endArray;
1484-
readToken(endArray);
1485-
return true;
1486-
}
14871481
int index = 0;
14881482
for (;;) {
1483+
skipSpaces();
1484+
if (current_ != end_ && *current_ == ']' && (index == 0 || (features_.allowTrailingCommas_ && !features_.allowDroppedNullPlaceholders_))) // empty array or trailing comma
1485+
{
1486+
Token endArray;
1487+
readToken(endArray);
1488+
return true;
1489+
}
14891490
Value& value = currentValue()[index++];
14901491
nodes_.push(&value);
14911492
bool ok = readValue();

test/data/fail_test_array_02.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[1,,]

test/data/test_array_08.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.=[]
2+
.[0]=1

test/data/test_array_08.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[1,]

0 commit comments

Comments
 (0)