mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 02:49:00 +00:00
Don't crash on @file when file doesn't exist (fixes #265)
When @file is used and file doesn't exist, just treat it as a normal argument.
This commit is contained in:
parent
968e7e60b7
commit
6048c6e2f0
@ -1,5 +1,10 @@
|
||||
2018-12-23 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* When specifying @arg on the command line, if the file "arg" does
|
||||
not exist, just treat this is a normal argument. This makes it
|
||||
easier to deal with files whose names start with the @ character.
|
||||
Fixes #265.
|
||||
|
||||
* Tweak completion so it works with zsh as well using
|
||||
bashcompinit.
|
||||
|
||||
|
17
qpdf/qpdf.cc
17
qpdf/qpdf.cc
@ -1408,7 +1408,24 @@ ArgParser::handleArgFileArguments()
|
||||
new_argv.push_back(PointerHolder<char>(true, QUtil::copy_string(argv[0])));
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
char* argfile = 0;
|
||||
if ((strlen(argv[i]) > 1) && (argv[i][0] == '@'))
|
||||
{
|
||||
try
|
||||
{
|
||||
argfile = 1 + argv[i];
|
||||
if (strcmp(argfile, "-") != 0)
|
||||
{
|
||||
fclose(QUtil::safe_fopen(argfile, "rb"));
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error&)
|
||||
{
|
||||
// The file's not there; treating as regular option
|
||||
argfile = 0;
|
||||
}
|
||||
}
|
||||
if (argfile)
|
||||
{
|
||||
readArgsFromFile(1+argv[i]);
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ foreach my $c (@completion_tests)
|
||||
show_ntests();
|
||||
# ----------
|
||||
$td->notify("--- Argument Parsing ---");
|
||||
$n_tests += 3;
|
||||
$n_tests += 4;
|
||||
|
||||
$td->runtest("required argument",
|
||||
{$td->COMMAND => "qpdf --password minimal.pdf"},
|
||||
@ -167,6 +167,11 @@ $td->runtest("required argument with choices",
|
||||
{$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}",
|
||||
$td->EXIT_STATUS => 2},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
copy("minimal.pdf", '@file.pdf');
|
||||
$td->runtest("\@file exists and file doesn't",
|
||||
{$td->COMMAND => "qpdf --check \@file.pdf"},
|
||||
{$td->FILE => "check-at-file.out", $td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
show_ntests();
|
||||
# ----------
|
||||
@ -1100,6 +1105,7 @@ $td->notify("--- Overwrite self ---");
|
||||
$n_tests += 1;
|
||||
|
||||
copy("minimal.pdf", "a.pdf");
|
||||
# Also tests @- for reading args from stdin
|
||||
$td->runtest("don't overwrite self",
|
||||
{$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"},
|
||||
{$td->REGEXP => "input file and output file are the same.*",
|
||||
@ -3384,5 +3390,5 @@ sub get_md5_checksum
|
||||
sub cleanup
|
||||
{
|
||||
system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
|
||||
system("rm -rf *split-out* ???-kfo.pdf *.tmpout");
|
||||
system("rm -rf *split-out* ???-kfo.pdf *.tmpout \@file.pdf");
|
||||
}
|
||||
|
6
qpdf/qtest/qpdf/check-at-file.out
Normal file
6
qpdf/qtest/qpdf/check-at-file.out
Normal file
@ -0,0 +1,6 @@
|
||||
checking @file.pdf
|
||||
PDF Version: 1.3
|
||||
File is not encrypted
|
||||
File is not linearized
|
||||
No syntax or stream encoding errors found; the file may still contain
|
||||
errors that qpdf cannot detect
|
Loading…
Reference in New Issue
Block a user