Cleanup some Json::Value methods:

* Rename isArray to isArrayOrNull
* Rename isObject to isObjectOrNull
* Introduce isArray and isObject
* Change as many uses of isArrayorNull to isArray as possible
* Change as many uses of isObjectorNull to isObject as possible
* Reject null JSON arrays for subscribe and unsubscribe
This commit is contained in:
Howard Hinnant
2018-02-01 15:23:41 -05:00
committed by Mike Ellery
parent 20defb4844
commit 1a245234f1
24 changed files with 90 additions and 63 deletions

View File

@@ -495,7 +495,7 @@ static boost::optional<detail::STVar> parseLeaf (
break;
case STI_VECTOR256:
if (! value.isArray ())
if (! value.isArrayOrNull ())
{
error = array_expected (json_name, fieldName);
return ret;
@@ -521,7 +521,7 @@ static boost::optional<detail::STVar> parseLeaf (
break;
case STI_PATHSET:
if (!value.isArray ())
if (!value.isArrayOrNull ())
{
error = array_expected (json_name, fieldName);
return ret;
@@ -535,7 +535,7 @@ static boost::optional<detail::STVar> parseLeaf (
{
STPath p;
if (!value[i].isArray ())
if (!value[i].isArrayOrNull ())
{
std::stringstream ss;
ss << fieldName << "[" << i << "]";
@@ -555,7 +555,7 @@ static boost::optional<detail::STVar> parseLeaf (
Json::Value pathEl = value[i][j];
if (!pathEl.isObject ())
if (!pathEl.isObject())
{
error = not_an_object (element_name);
return ret;
@@ -709,7 +709,7 @@ static boost::optional <STObject> parseObject (
int depth,
Json::Value& error)
{
if (! json.isObject ())
if (! json.isObjectOrNull ())
{
error = not_an_object (json_name);
return boost::none;
@@ -743,7 +743,7 @@ static boost::optional <STObject> parseObject (
case STI_TRANSACTION:
case STI_LEDGERENTRY:
case STI_VALIDATION:
if (! value.isObject ())
if (! value.isObjectOrNull ())
{
error = not_an_object (json_name, fieldName);
return boost::none;
@@ -816,7 +816,7 @@ static boost::optional <detail::STVar> parseArray (
int depth,
Json::Value& error)
{
if (! json.isArray ())
if (! json.isArrayOrNull ())
{
error = not_an_array (json_name);
return boost::none;
@@ -834,11 +834,12 @@ static boost::optional <detail::STVar> parseArray (
for (Json::UInt i = 0; json.isValidIndex (i); ++i)
{
bool const isObject (json[i].isObject());
bool const singleKey (isObject ? json[i].size() == 1 : true);
bool const isObjectOrNull (json[i].isObjectOrNull());
bool const singleKey (isObjectOrNull ? json[i].size() == 1 : true);
if (!isObject || !singleKey)
if (!isObjectOrNull || !singleKey)
{
// null values are !singleKey
error = singleton_expected (json_name, i);
return boost::none;
}