Skip to content

Commit d29705a

Browse files
committed
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.
1 parent 77d7559 commit d29705a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

resources/share/shared/bootstrap/bootstrap.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@
7171
}
7272
]
7373
},
74-
"wasLoadedFromFile": false,
74+
"wasLoadedFromFile": false
7575
}

src/blackmisc/json.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,14 @@ namespace BlackMisc::Json
411411
QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat)
412412
{
413413
if (json.isEmpty()) { return QJsonObject(); }
414-
const QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8()));
414+
415+
QJsonParseError error {};
416+
const QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8(), &error));
417+
if (error.error != QJsonParseError::NoError)
418+
{
419+
throw CJsonException(error.errorString());
420+
}
421+
415422
return acceptCacheFormat ? Json::unwrapCache(jsonDoc.object()) : jsonDoc.object();
416423
}
417424

0 commit comments

Comments
 (0)