mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 18:34:25 +01:00
Fix JSON Bug
Json::Values do not necessarily need to be JSON objects. This Patch checks if the JSON::Value is in deed an object. Reported-by: Markus Dollinger <dolli@ignifax.de> Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
c31deb10dc
commit
ab8f33ebb1
@ -9,11 +9,14 @@ template <typename T>
|
|||||||
T getJson(const Json::Value &root, const std::string &key);
|
T getJson(const Json::Value &root, const std::string &key);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T getJsonOrFail(const Json::Value &root, const std::string &key)
|
static T getJsonOrFail(const Json::Value &root, const std::string &key)
|
||||||
{
|
{
|
||||||
const auto members = root.getMemberNames();
|
if (root.isObject() == false)
|
||||||
if (std::find(members.begin(), members.end(), key) == members.end())
|
|
||||||
{
|
{
|
||||||
|
throw std::runtime_error("Invalid Json Object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.isMember(key) == false) {
|
||||||
throw std::runtime_error("Json key \"" + key + "\" not existing");
|
throw std::runtime_error("Json key \"" + key + "\" not existing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user