limit allowed types for JSON Query

limited allowed types for JSON::Query to Object, Array, Object::Ptr,
Array::Ptr and empty
This commit is contained in:
Aleksandar Fabijanic
2013-06-07 23:37:02 -05:00
parent 5e6ef1c14d
commit b61b5ae53d
4 changed files with 19 additions and 2 deletions

View File

@@ -77,7 +77,8 @@ Release 1.5.2 (2013-06-xx)
ignore precision == 0
- fixed GH #138: FreeBSD JSON tests fail
- fixed GH #99: JSON::Query an JSON::Object
- limited allowed types for JSON::Query to Object, Array, Object::Ptr,
Array::Ptr and empty
Release 1.5.1 (2013-01-11)
==========================

View File

@@ -53,7 +53,9 @@ class JSON_API Query
{
public:
Query(const Dynamic::Var& source);
/// Constructor. Pass the start object/array or Ptr thereof.
/// Creates the Query; source must be JSON Object, Array, Object::Ptr,
/// Array::Ptr or empty Var. Any other type will trigger throwing of
/// InvalidArgumentException.
/// Creating Query holding Ptr will typically result in faster
/// performance.

View File

@@ -50,6 +50,12 @@ namespace JSON {
Query::Query(const Var& source): _source(source)
{
if (!source.isEmpty() &&
source.type() != typeid(Object) &&
source.type() != typeid(Object::Ptr) &&
source.type() != typeid(Array) &&
source.type() != typeid(Array::Ptr))
throw InvalidArgumentException("Only JSON Object, Array or pointers thereof allowed.");
}

View File

@@ -1096,6 +1096,14 @@ void JSONTest::testQuery()
Query queryObj(*pObj);
Var idQueryObj = queryObj.find("Id");
assert (22 == idQueryObj);
Var bad = 1;
try
{
Query badQuery(bad);
fail ("must throw");
}
catch (Poco::InvalidArgumentException&) { }
}