Skip to content

Commit 3beb37e

Browse files
authored
revert trailing comma in old Reader (open-source-parsers#1126)
1 parent dc180eb commit 3beb37e

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

include/json/json_features.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class JSON_API Features {
2323
/** \brief A configuration that allows all features and assumes all strings
2424
* are UTF-8.
2525
* - C & C++ comments are allowed
26-
* - Trailing commas in objects and arrays are allowed.
2726
* - Root object can be any JSON value
2827
* - Assumes Value strings are encoded in UTF-8
2928
*/
@@ -32,7 +31,6 @@ class JSON_API Features {
3231
/** \brief A configuration that is strictly compatible with the JSON
3332
* specification.
3433
* - Comments are forbidden.
35-
* - Trailing commas in objects and arrays are forbidden.
3634
* - Root object must be either an array or an object value.
3735
* - Assumes Value strings are encoded in UTF-8
3836
*/
@@ -45,10 +43,6 @@ class JSON_API Features {
4543
/// \c true if comments are allowed. Default: \c true.
4644
bool allowComments_{true};
4745

48-
/// \c true if trailing commas in objects and arrays are allowed. Default \c
49-
/// true.
50-
bool allowTrailingCommas_{true};
51-
5246
/// \c true if root must be either an array or an object value. Default: \c
5347
/// false.
5448
bool strictRoot_{false};

src/lib_json/json_reader.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ Features Features::all() { return {}; }
6767
Features Features::strictMode() {
6868
Features features;
6969
features.allowComments_ = false;
70-
features.allowTrailingCommas_ = false;
7170
features.strictRoot_ = true;
7271
features.allowDroppedNullPlaceholders_ = false;
7372
features.allowNumericKeys_ = false;
@@ -455,9 +454,7 @@ bool Reader::readObject(Token& token) {
455454
initialTokenOk = readToken(tokenName);
456455
if (!initialTokenOk)
457456
break;
458-
if (tokenName.type_ == tokenObjectEnd &&
459-
(name.empty() ||
460-
features_.allowTrailingCommas_)) // empty object or trailing comma
457+
if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
461458
return true;
462459
name.clear();
463460
if (tokenName.type_ == tokenString) {
@@ -505,20 +502,15 @@ bool Reader::readArray(Token& token) {
505502
Value init(arrayValue);
506503
currentValue().swapPayload(init);
507504
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+
}
508512
int index = 0;
509513
for (;;) {
510-
skipSpaces();
511-
if (current_ != end_ && *current_ == ']' &&
512-
(index == 0 ||
513-
(features_.allowTrailingCommas_ &&
514-
!features_.allowDroppedNullPlaceholders_))) // empty array or trailing
515-
// comma
516-
{
517-
Token endArray;
518-
readToken(endArray);
519-
return true;
520-
}
521-
522514
Value& value = currentValue()[index++];
523515
nodes_.push(&value);
524516
bool ok = readValue();

0 commit comments

Comments
 (0)