diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 2e0abb43..3bdb4f39 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -2446,6 +2446,10 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea auto n_collate = m->collate.size(); auto n_specs = parsed_specs.size(); + if (!(n_collate == 0 || n_collate == 1 || n_collate == n_specs)) { + usage("--pages: if --collate has more than one value, it must have one value per page " + "specification"); + } if (n_collate > 0 && n_specs > 1) { // Collate the pages by selecting one page from each spec in order. When a spec runs out of // pages, stop selecting from it. diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index e48d7e31..db6c5948 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -957,11 +957,6 @@ QPDFJob::PagesConfig::endPages() if (n_specs == 0) { usage("--pages: no page specifications given"); } - auto n_collate = config->o.m->collate.size(); - if (!(n_collate == 0 || n_collate == 1 || n_collate == n_specs)) { - usage("--pages: if --collate has more than one value, it must have one value per page " - "specification"); - } return this->config; } diff --git a/qpdf/qtest/arg-parsing.test b/qpdf/qtest/arg-parsing.test index 82594674..297141d4 100644 --- a/qpdf/qtest/arg-parsing.test +++ b/qpdf/qtest/arg-parsing.test @@ -15,7 +15,7 @@ cleanup(); my $td = new TestDriver('arg-parsing'); -my $n_tests = 23; +my $n_tests = 24; $td->runtest("required argument", {$td->COMMAND => "qpdf --password minimal.pdf"}, @@ -101,6 +101,13 @@ $td->runtest("wrong number of collate args", {$td->REGEXP => ".*--collate has more than one value.*", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +$td->runtest("wrong number of collate args", + {$td->COMMAND => + "qpdf collate-odd.pdf --pages . minimal.pdf collate-even.pdf --" . + " --collate=2,3 a.pdf"}, + {$td->REGEXP => ".*--collate has more than one value.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); # Ignoring -- at the top level was never intended but turned out to # have been there for a long time so that people relied on it. It is