mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 00:49:46 +02:00
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:
@@ -77,7 +77,8 @@ Release 1.5.2 (2013-06-xx)
|
|||||||
ignore precision == 0
|
ignore precision == 0
|
||||||
- fixed GH #138: FreeBSD JSON tests fail
|
- fixed GH #138: FreeBSD JSON tests fail
|
||||||
- fixed GH #99: JSON::Query an JSON::Object
|
- 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)
|
Release 1.5.1 (2013-01-11)
|
||||||
==========================
|
==========================
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ class JSON_API Query
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Query(const Dynamic::Var& source);
|
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
|
/// Creating Query holding Ptr will typically result in faster
|
||||||
/// performance.
|
/// performance.
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ namespace JSON {
|
|||||||
|
|
||||||
Query::Query(const Var& source): _source(source)
|
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1096,6 +1096,14 @@ void JSONTest::testQuery()
|
|||||||
Query queryObj(*pObj);
|
Query queryObj(*pObj);
|
||||||
Var idQueryObj = queryObj.find("Id");
|
Var idQueryObj = queryObj.find("Id");
|
||||||
assert (22 == idQueryObj);
|
assert (22 == idQueryObj);
|
||||||
|
|
||||||
|
Var bad = 1;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Query badQuery(bad);
|
||||||
|
fail ("must throw");
|
||||||
|
}
|
||||||
|
catch (Poco::InvalidArgumentException&) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user