aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/JSON.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-07-24 22:17:03 +0200
committerJay Berkenbilt <ejb@ql.org>2022-07-24 22:17:03 +0200
commitf8d1ab946205440ed3c44511ef42e5ad13fb9e5e (patch)
treeb9cae2ce60a010300777528063932d80307a7746 /libqpdf/JSON.cc
parentb3e6d445cbf73da2b00062c3f639c2453041ee41 (diff)
downloadqpdf-f8d1ab946205440ed3c44511ef42e5ad13fb9e5e.tar.zst
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.
Diffstat (limited to 'libqpdf/JSON.cc')
-rw-r--r--libqpdf/JSON.cc27
1 files changed, 14 insertions, 13 deletions
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");