mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-13 10:22:55 +01:00
Allow trailing comma in arrays if dropped null placeholders are not allowed
This commit is contained in:
parent
01db7b7430
commit
554d961625
@ -503,15 +503,16 @@ bool Reader::readArray(Token& token) {
|
||||
Value init(arrayValue);
|
||||
currentValue().swapPayload(init);
|
||||
currentValue().setOffsetStart(token.start_ - begin_);
|
||||
skipSpaces();
|
||||
if (current_ != end_ && *current_ == ']') // empty array
|
||||
{
|
||||
Token endArray;
|
||||
readToken(endArray);
|
||||
return true;
|
||||
}
|
||||
int index = 0;
|
||||
for (;;) {
|
||||
skipSpaces();
|
||||
if (current_ != end_ && *current_ == ']' && (index == 0 || (features_.allowTrailingCommas_ && !features_.allowDroppedNullPlaceholders_))) // empty array or trailing comma
|
||||
{
|
||||
Token endArray;
|
||||
readToken(endArray);
|
||||
return true;
|
||||
}
|
||||
|
||||
Value& value = currentValue()[index++];
|
||||
nodes_.push(&value);
|
||||
bool ok = readValue();
|
||||
@ -1493,15 +1494,15 @@ bool OurReader::readArray(Token& token) {
|
||||
Value init(arrayValue);
|
||||
currentValue().swapPayload(init);
|
||||
currentValue().setOffsetStart(token.start_ - begin_);
|
||||
skipSpaces();
|
||||
if (current_ != end_ && *current_ == ']') // empty array
|
||||
{
|
||||
Token endArray;
|
||||
readToken(endArray);
|
||||
return true;
|
||||
}
|
||||
int index = 0;
|
||||
for (;;) {
|
||||
skipSpaces();
|
||||
if (current_ != end_ && *current_ == ']' && (index == 0 || (features_.allowTrailingCommas_ && !features_.allowDroppedNullPlaceholders_))) // empty array or trailing comma
|
||||
{
|
||||
Token endArray;
|
||||
readToken(endArray);
|
||||
return true;
|
||||
}
|
||||
Value& value = currentValue()[index++];
|
||||
nodes_.push(&value);
|
||||
bool ok = readValue();
|
||||
|
1
test/data/fail_test_array_02.json
Normal file
1
test/data/fail_test_array_02.json
Normal file
@ -0,0 +1 @@
|
||||
[1,,]
|
2
test/data/test_array_08.expected
Normal file
2
test/data/test_array_08.expected
Normal file
@ -0,0 +1,2 @@
|
||||
.=[]
|
||||
.[0]=1
|
1
test/data/test_array_08.json
Normal file
1
test/data/test_array_08.json
Normal file
@ -0,0 +1 @@
|
||||
[1,]
|
Loading…
Reference in New Issue
Block a user