Commit 20a134826c6f33fab81b0cdb9ba2d75fb03d1b59

Authored by Jay Berkenbilt
1 parent 8b0ae8bb

Fix arg parsing check with --collate

The check for the number of items was in the wrong place.
libqpdf/QPDFJob.cc
@@ -2446,6 +2446,10 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_hea @@ -2446,6 +2446,10 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_hea
2446 2446
2447 auto n_collate = m->collate.size(); 2447 auto n_collate = m->collate.size();
2448 auto n_specs = parsed_specs.size(); 2448 auto n_specs = parsed_specs.size();
  2449 + if (!(n_collate == 0 || n_collate == 1 || n_collate == n_specs)) {
  2450 + usage("--pages: if --collate has more than one value, it must have one value per page "
  2451 + "specification");
  2452 + }
2449 if (n_collate > 0 && n_specs > 1) { 2453 if (n_collate > 0 && n_specs > 1) {
2450 // Collate the pages by selecting one page from each spec in order. When a spec runs out of 2454 // Collate the pages by selecting one page from each spec in order. When a spec runs out of
2451 // pages, stop selecting from it. 2455 // pages, stop selecting from it.
libqpdf/QPDFJob_config.cc
@@ -957,11 +957,6 @@ QPDFJob::PagesConfig::endPages() @@ -957,11 +957,6 @@ QPDFJob::PagesConfig::endPages()
957 if (n_specs == 0) { 957 if (n_specs == 0) {
958 usage("--pages: no page specifications given"); 958 usage("--pages: no page specifications given");
959 } 959 }
960 - auto n_collate = config->o.m->collate.size();  
961 - if (!(n_collate == 0 || n_collate == 1 || n_collate == n_specs)) {  
962 - usage("--pages: if --collate has more than one value, it must have one value per page "  
963 - "specification");  
964 - }  
965 return this->config; 960 return this->config;
966 } 961 }
967 962
qpdf/qtest/arg-parsing.test
@@ -15,7 +15,7 @@ cleanup(); @@ -15,7 +15,7 @@ cleanup();
15 15
16 my $td = new TestDriver('arg-parsing'); 16 my $td = new TestDriver('arg-parsing');
17 17
18 -my $n_tests = 23; 18 +my $n_tests = 24;
19 19
20 $td->runtest("required argument", 20 $td->runtest("required argument",
21 {$td->COMMAND => "qpdf --password minimal.pdf"}, 21 {$td->COMMAND => "qpdf --password minimal.pdf"},
@@ -101,6 +101,13 @@ $td->runtest("wrong number of collate args", @@ -101,6 +101,13 @@ $td->runtest("wrong number of collate args",
101 {$td->REGEXP => ".*--collate has more than one value.*", 101 {$td->REGEXP => ".*--collate has more than one value.*",
102 $td->EXIT_STATUS => 2}, 102 $td->EXIT_STATUS => 2},
103 $td->NORMALIZE_NEWLINES); 103 $td->NORMALIZE_NEWLINES);
  104 +$td->runtest("wrong number of collate args",
  105 + {$td->COMMAND =>
  106 + "qpdf collate-odd.pdf --pages . minimal.pdf collate-even.pdf --" .
  107 + " --collate=2,3 a.pdf"},
  108 + {$td->REGEXP => ".*--collate has more than one value.*",
  109 + $td->EXIT_STATUS => 2},
  110 + $td->NORMALIZE_NEWLINES);
104 111
105 # Ignoring -- at the top level was never intended but turned out to 112 # Ignoring -- at the top level was never intended but turned out to
106 # have been there for a long time so that people relied on it. It is 113 # have been there for a long time so that people relied on it. It is