Small enhancement to --pages argument parsing

This commit is contained in:
Jay Berkenbilt 2020-11-09 11:12:34 -05:00
parent 47f4ebcdac
commit a7ef572c84
5 changed files with 26 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2020-11-09 Jay Berkenbilt <ejb@ql.org>
* Handle "." appearing in --pages not preceded by a numeric range
as a special case in comand-line parsing code.
2020-11-04 Jay Berkenbilt <ejb@ql.org>
* Ignore the value of the offset/generation field in an xref entry

View File

@ -2877,9 +2877,17 @@ ArgParser::parsePagesOptions()
// The range is invalid. Let's see if it's a file.
try
{
fclose(QUtil::safe_fopen(range, "rb"));
// Yup, it's a file.
QTC::TC("qpdf", "qpdf pages range omitted in middle");
if (strcmp(range, ".") == 0)
{
// "." means the input file.
QTC::TC("qpdf", "qpdf pages range omitted with .");
}
else
{
fclose(QUtil::safe_fopen(range, "rb"));
QTC::TC("qpdf", "qpdf pages range omitted in middle");
// Yup, it's a file.
}
range_omitted = true;
}
catch (std::runtime_error&)

View File

@ -456,3 +456,4 @@ qpdf found shared xobject in leaf 0
QPDF copy foreign with data 1
QPDF copy foreign with foreign_stream 1
QPDFObjectHandle need_newline 1
qpdf pages range omitted with . 0

View File

@ -2093,7 +2093,7 @@ foreach my $f (qw(page_api_2 direct-pages))
show_ntests();
# ----------
$td->notify("--- Merging and Splitting ---");
$n_tests += 26;
$n_tests += 28;
# Select pages from the same file multiple times including selecting
# twice from an encrypted file and specifying the password only the
@ -2149,6 +2149,14 @@ $td->runtest("merge with implicit ranges",
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "merge-implicit-ranges.pdf"});
$td->runtest("merge with . and implicit ranges",
{$td->COMMAND =>
"qpdf minimal.pdf a.pdf --pages minimal.pdf . 1 --" .
" --static-id"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "merge-dot-implicit-ranges.pdf"});
$td->runtest("merge with multiple labels",
{$td->COMMAND =>
"qpdf --empty a.pdf" .

Binary file not shown.