diff --git a/CHANGELOG b/CHANGELOG index 7b92330c7..abeb430bb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) ========================== diff --git a/JSON/include/Poco/JSON/Query.h b/JSON/include/Poco/JSON/Query.h index af93b897f..b6151f3d0 100644 --- a/JSON/include/Poco/JSON/Query.h +++ b/JSON/include/Poco/JSON/Query.h @@ -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. diff --git a/JSON/src/Query.cpp b/JSON/src/Query.cpp index e54388fd7..7df18092e 100644 --- a/JSON/src/Query.cpp +++ b/JSON/src/Query.cpp @@ -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."); } diff --git a/JSON/testsuite/src/JSONTest.cpp b/JSON/testsuite/src/JSONTest.cpp index 3914f0654..548eb22f1 100644 --- a/JSON/testsuite/src/JSONTest.cpp +++ b/JSON/testsuite/src/JSONTest.cpp @@ -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&) { } }