From f8d1ab946205440ed3c44511ef42e5ad13fb9e5e Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 24 Jul 2022 16:17:03 -0400 Subject: JSON schema -- accept single item in place of array When the schema wants a variable-length array, allow a single item as well as allowing an array. --- libqpdf/JSON.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'libqpdf/JSON.cc') diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 8f4e75a2..7bd2337f 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -538,26 +538,27 @@ JSON::checkSchemaInternal( } } } else if (sch_arr) { - if (!this_arr) { - QTC::TC("libtests", "JSON wanted array"); - errors.push_back(err_prefix + " is supposed to be an array"); - return false; - } if (sch_arr->elements.size() != 1) { QTC::TC("libtests", "JSON schema array error"); errors.push_back( err_prefix + " schema array contains other than one item"); return false; } - int i = 0; - for (auto const& element: this_arr->elements) { + if (this_arr) { + int i = 0; + for (auto const& element: this_arr->elements) { + checkSchemaInternal( + element.get(), + sch_arr->elements.at(0).get(), + flags, + errors, + prefix + "." + QUtil::int_to_string(i)); + ++i; + } + } else { + QTC::TC("libtests", "JSON schema array for single item"); checkSchemaInternal( - element.get(), - sch_arr->elements.at(0).get(), - flags, - errors, - prefix + "." + QUtil::int_to_string(i)); - ++i; + this_v, sch_arr->elements.at(0).get(), flags, errors, prefix); } } else if (!sch_str) { QTC::TC("libtests", "JSON schema other type"); -- cgit v1.2.3-54-g00ecf