Skip to content

Commit

Permalink
Throw error when parsed JSON is invalid
Browse files Browse the repository at this point in the history
Without this error detection, the malformed bootstrap.json
stayed undetected. Hence, the old VATSIM FSD HTTP URL was used.
  • Loading branch information
ltoenning committed Oct 5, 2023
1 parent 77d7559 commit d29705a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/share/shared/bootstrap/bootstrap.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@
}
]
},
"wasLoadedFromFile": false,
"wasLoadedFromFile": false
}
9 changes: 8 additions & 1 deletion src/blackmisc/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,14 @@ namespace BlackMisc::Json
QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat)
{
if (json.isEmpty()) { return QJsonObject(); }
const QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8()));

QJsonParseError error {};
const QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8(), &error));
if (error.error != QJsonParseError::NoError)
{
throw CJsonException(error.errorString());
}

return acceptCacheFormat ? Json::unwrapCache(jsonDoc.object()) : jsonDoc.object();
}

Expand Down

0 comments on commit d29705a

Please sign in to comment.