Skip to content

revert trailing comma in old Reader #1126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions include/json/json_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class JSON_API Features {
/** \brief A configuration that allows all features and assumes all strings
* are UTF-8.
* - C & C++ comments are allowed
* - Trailing commas in objects and arrays are allowed.
* - Root object can be any JSON value
* - Assumes Value strings are encoded in UTF-8
*/
Expand All @@ -32,7 +31,6 @@ class JSON_API Features {
/** \brief A configuration that is strictly compatible with the JSON
* specification.
* - Comments are forbidden.
* - Trailing commas in objects and arrays are forbidden.
* - Root object must be either an array or an object value.
* - Assumes Value strings are encoded in UTF-8
*/
Expand All @@ -45,10 +43,6 @@ class JSON_API Features {
/// \c true if comments are allowed. Default: \c true.
bool allowComments_{true};

/// \c true if trailing commas in objects and arrays are allowed. Default \c
/// true.
bool allowTrailingCommas_{true};

/// \c true if root must be either an array or an object value. Default: \c
/// false.
bool strictRoot_{false};
Expand Down
24 changes: 8 additions & 16 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Features Features::all() { return {}; }
Features Features::strictMode() {
Features features;
features.allowComments_ = false;
features.allowTrailingCommas_ = false;
features.strictRoot_ = true;
features.allowDroppedNullPlaceholders_ = false;
features.allowNumericKeys_ = false;
Expand Down Expand Up @@ -455,9 +454,7 @@ bool Reader::readObject(Token& token) {
initialTokenOk = readToken(tokenName);
if (!initialTokenOk)
break;
if (tokenName.type_ == tokenObjectEnd &&
(name.empty() ||
features_.allowTrailingCommas_)) // empty object or trailing comma
if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
return true;
name.clear();
if (tokenName.type_ == tokenString) {
Expand Down Expand Up @@ -505,20 +502,15 @@ 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();
Expand Down