diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-05-06 23:49:28 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-05-07 14:26:31 +0200 |
commit | 7f65a5c21f83df31f3732532f0d836f32c982d67 (patch) | |
tree | d2a0528a4df6403a3024c27e15af0cd47eca68ff /libqpdf/QPDFJob.cc | |
parent | a3c99803954ad0f3762d986c953666c6517cad0c (diff) | |
download | qpdf-7f65a5c21f83df31f3732532f0d836f32c982d67.tar.zst |
Test json against schema only on demand
Testing json against schema requires an in-memory copy, so do it only
when requested by the test suite.
Diffstat (limited to 'libqpdf/QPDFJob.cc')
-rw-r--r-- | libqpdf/QPDFJob.cc | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 1e456f24..468a0046 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -16,6 +16,7 @@ #include <qpdf/Pl_Flate.hh> #include <qpdf/Pl_OStream.hh> #include <qpdf/Pl_StdioFile.hh> +#include <qpdf/Pl_String.hh> #include <qpdf/QTC.hh> #include <qpdf/QUtil.hh> @@ -1592,6 +1593,13 @@ QPDFJob::json_out_schema_v1() void QPDFJob::doJSON(QPDF& pdf, Pipeline* p) { + std::string captured_json; + std::shared_ptr<Pl_String> pl_str; + if (this->m->test_json_schema) { + pl_str = std::make_shared<Pl_String>("capture json", p, captured_json); + p = pl_str.get(); + } + JSON j = JSON::makeDictionary(); // This version is updated every time a non-backward-compatible // change is made to the JSON format. Clients of the JSON are to @@ -1651,23 +1659,22 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) doJSONObjectinfo(pdf, j); } - // Check against schema + *p << j.unparse() << "\n"; - JSON schema = json_schema(&m->json_keys); - std::list<std::string> errors; - if (!j.checkSchema(schema, errors)) { - *(this->m->cerr) - << "QPDFJob didn't create JSON that complies with its own rules.\n\ -Please report this as a bug at\n\ - https://github.com/qpdf/qpdf/issues/new\n\ -ideally with the file that caused the error and the output below. Thanks!\n\ -\n"; - for (auto const& error: errors) { - *(this->m->cerr) << error << std::endl; + if (this->m->test_json_schema) { + // Check against schema + JSON schema = json_schema(&m->json_keys); + std::list<std::string> errors; + JSON captured = JSON::parse(captured_json); + if (!captured.checkSchema(schema, errors)) { + *(this->m->cerr) << "QPDFJob didn't create JSON that complies with" + " its own rules." + << std::endl; + for (auto const& error: errors) { + *(this->m->cerr) << error << std::endl; + } } } - - *p << j.unparse() << "\n"; } void |