Skip to content

Commit b61b5ae

Browse files
committed
limit allowed types for JSON Query
limited allowed types for JSON::Query to Object, Array, Object::Ptr, Array::Ptr and empty
1 parent 5e6ef1c commit b61b5ae

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎CHANGELOG‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ Release 1.5.2 (2013-06-xx)
7777
ignore precision == 0
7878
- fixed GH #138: FreeBSD JSON tests fail
7979
- fixed GH #99: JSON::Query an JSON::Object
80-
80+
- limited allowed types for JSON::Query to Object, Array, Object::Ptr,
81+
Array::Ptr and empty
8182

8283
Release 1.5.1 (2013-01-11)
8384
==========================

‎JSON/include/Poco/JSON/Query.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class JSON_API Query
5353
{
5454
public:
5555
Query(const Dynamic::Var& source);
56-
/// Constructor. Pass the start object/array or Ptr thereof.
56+
/// Creates the Query; source must be JSON Object, Array, Object::Ptr,
57+
/// Array::Ptr or empty Var. Any other type will trigger throwing of
58+
/// InvalidArgumentException.
5759
/// Creating Query holding Ptr will typically result in faster
5860
/// performance.
5961

‎JSON/src/Query.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ namespace JSON {
5050

5151
Query::Query(const Var& source): _source(source)
5252
{
53+
if (!source.isEmpty() &&
54+
source.type() != typeid(Object) &&
55+
source.type() != typeid(Object::Ptr) &&
56+
source.type() != typeid(Array) &&
57+
source.type() != typeid(Array::Ptr))
58+
throw InvalidArgumentException("Only JSON Object, Array or pointers thereof allowed.");
5359
}
5460

5561

‎JSON/testsuite/src/JSONTest.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,14 @@ void JSONTest::testQuery()
10961096
Query queryObj(*pObj);
10971097
Var idQueryObj = queryObj.find("Id");
10981098
assert (22 == idQueryObj);
1099+
1100+
Var bad = 1;
1101+
try
1102+
{
1103+
Query badQuery(bad);
1104+
fail ("must throw");
1105+
}
1106+
catch (Poco::InvalidArgumentException&) { }
10991107
}
11001108

11011109

0 commit comments

Comments
 (0)