Skip to content

Commit 554d961

Browse files
kimsey0cdunn2001
authored andcommitted
Allow trailing comma in arrays if dropped null placeholders are not allowed
1 parent 01db7b7 commit 554d961

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
@@ -503,15 +503,16 @@ bool Reader::readArray(Token& token) {
503503
Value init(arrayValue);
504504
currentValue().swapPayload(init);
505505
currentValue().setOffsetStart(token.start_ - begin_);
506-
skipSpaces();
507-
if (current_ != end_ && *current_ == ']') // empty array
508-
{
509-
Token endArray;
510-
readToken(endArray);
511-
return true;
512-
}
513506
int index = 0;
514507
for (;;) {
508+
skipSpaces();
509+
if (current_ != end_ && *current_ == ']' && (index == 0 || (features_.allowTrailingCommas_ && !features_.allowDroppedNullPlaceholders_))) // empty array or trailing comma
510+
{
511+
Token endArray;
512+
readToken(endArray);
513+
return true;
514+
}
515+
515516
Value& value = currentValue()[index++];
516517
nodes_.push(&value);
517518
bool ok = readValue();
@@ -1493,15 +1494,15 @@ bool OurReader::readArray(Token& token) {
14931494
Value init(arrayValue);
14941495
currentValue().swapPayload(init);
14951496
currentValue().setOffsetStart(token.start_ - begin_);
1496-
skipSpaces();
1497-
if (current_ != end_ && *current_ == ']') // empty array
1498-
{
1499-
Token endArray;
1500-
readToken(endArray);
1501-
return true;
1502-
}
15031497
int index = 0;
15041498
for (;;) {
1499+
skipSpaces();
1500+
if (current_ != end_ && *current_ == ']' && (index == 0 || (features_.allowTrailingCommas_ && !features_.allowDroppedNullPlaceholders_))) // empty array or trailing comma
1501+
{
1502+
Token endArray;
1503+
readToken(endArray);
1504+
return true;
1505+
}
15051506
Value& value = currentValue()[index++];
15061507
nodes_.push(&value);
15071508
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)