Added test for malformed JSON.

This commit is contained in:
tastytea 2019-04-15 03:48:39 +02:00
parent f84a272f53
commit 5408f6f235
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 9 additions and 2 deletions

View File

@ -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