From d29705a01b8ddf381c638ea1b627d1f0bce68400 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Wed, 4 Oct 2023 15:40:35 +0200 Subject: [PATCH] Throw error when parsed JSON is invalid Without this error detection, the malformed bootstrap.json stayed undetected. Hence, the old VATSIM FSD HTTP URL was used. --- resources/share/shared/bootstrap/bootstrap.json | 2 +- src/blackmisc/json.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/resources/share/shared/bootstrap/bootstrap.json b/resources/share/shared/bootstrap/bootstrap.json index 331dec2d1..eea8dfd34 100644 --- a/resources/share/shared/bootstrap/bootstrap.json +++ b/resources/share/shared/bootstrap/bootstrap.json @@ -71,5 +71,5 @@ } ] }, - "wasLoadedFromFile": false, + "wasLoadedFromFile": false } diff --git a/src/blackmisc/json.cpp b/src/blackmisc/json.cpp index 98c650ec8..f27189340 100644 --- a/src/blackmisc/json.cpp +++ b/src/blackmisc/json.cpp @@ -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(); }