From 5408f6f2350dd72e8cd85d4c043cffea0b8edff3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 15 Apr 2019 03:48:39 +0200 Subject: [PATCH] Added test for malformed JSON. --- src/easy/entity.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/easy/entity.cpp b/src/easy/entity.cpp index 06534b3..db809f3 100644 --- a/src/easy/entity.cpp +++ b/src/easy/entity.cpp @@ -54,8 +54,15 @@ Easy::Entity::operator const Json::Value() const void Easy::Entity::from_string(const string &json) { - std::stringstream ss(json); - ss >> _tree; + if (json.find('{') != std::string::npos) + { + std::stringstream ss(json); + ss >> _tree; + } + else + { + _tree.clear(); + } // If the JSON is a single object encapsulated in an array, // transform it into an object. If the JSON string is [], transform to null