Commit d0b7cc8ac6773e3ddab1c34da910072fac441d07

Authored by Jay Berkenbilt
1 parent 63c5a56f

QPDFJob json: make removeAttachment take an array (fixes #693)

ChangeLog
1 1 2022-04-24 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Bug fix: "removeAttachment" in the job JSON now takes an array
  4 + of strings instead of a string. It should have taken an array of
  5 + strings since the corresponding command-line argument,
  6 + --remove-attachment, is repeatable. Fixes #693.
  7 +
3 8 * Deprecate QPDFObjectHandle::replaceOrRemoveKey -- it does and
4 9 always has done the same thing as replaceKey.
5 10  
... ...
job.sums
... ... @@ -6,12 +6,12 @@ include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a3
6 6 include/qpdf/auto_job_c_main.hh 4ba9bcb8be945f6a3ffa0df3becdb8488b6eaf45dd914d8b714d948e17b5ad5d
7 7 include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec
8 8 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
9   -job.yml 06a0b29f63c1622a0c6270d15d848a42084a6424e4b98d5d4942a8ec903b7a70
  9 +job.yml c2937bb06818fc3bffe54c6c069a4a06db7f3c841958c2da1b2f4a33978fd24a
10 10 libqpdf/qpdf/auto_job_decl.hh 74df4d7fdbdf51ecd0d58ce1e9844bb5525b9adac5a45f7c9a787ecdda2868df
11 11 libqpdf/qpdf/auto_job_help.hh a7d7edc3b270f2488778426646bb68dcad036727db4be87d1da9993e2a007634
12 12 libqpdf/qpdf/auto_job_init.hh 6bd71c2ae4ba80e81fe5ae5517ba72abf53a3146f66864f99eeebc7d224998a5
13   -libqpdf/qpdf/auto_job_json_decl.hh 30058d744cfb0d1b5e5bd2830e1c7b24713ee39c97c4ccb723dbbae1f9fab61c
14   -libqpdf/qpdf/auto_job_json_init.hh d3885830362c4337822bf9bc3d177b50149ba403a26de0e69d37f7751cb5d538
15   -libqpdf/qpdf/auto_job_schema.hh 18a3780671d95224cb9a27dcac627c421cae509d59f33a63e6bda0ab53cce923
  13 +libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
  14 +libqpdf/qpdf/auto_job_json_init.hh 06d51f11c117011256e175386eee9946441f3c22b49dd91fc591bbc1fa3bbeec
  15 +libqpdf/qpdf/auto_job_schema.hh 43273b9edfc48b1f4cccbff1d2b31916a9057c474ef97d2936b2f1f14170885b
16 16 manual/_ext/qpdf.py e9ac9d6c70642a3d29281ee5ad92ae2422dee8be9306fb8a0bc9dba0ed5e28f3
17 17 manual/cli.rst aa44cbe7b6281ee05dc8b19ee1b12ca770503681ffc8ba90e795fc3c3b55153d
... ...
... ... @@ -372,6 +372,7 @@ json:
372 372 moddate:
373 373 replace:
374 374 remove-attachment:
  375 + - null
375 376 copy-attachments-from:
376 377 - _file: "file to copy attachments from"
377 378 CopyAtt.password:
... ...
libqpdf/QPDFJob_json.cc
... ... @@ -413,6 +413,17 @@ Handlers::setupAddAttachmentFile()
413 413 }
414 414  
415 415 void
  416 +Handlers::beginRemoveAttachmentArray(JSON)
  417 +{
  418 + // nothing needed
  419 +}
  420 +
  421 +void
  422 +Handlers::endRemoveAttachmentArray()
  423 +{
  424 + // nothing needed
  425 +}
  426 +void
416 427 Handlers::beginCopyAttachmentsFromArray(JSON)
417 428 {
418 429 // nothing needed
... ...
libqpdf/qpdf/auto_job_json_decl.hh
... ... @@ -29,6 +29,8 @@ void endAddAttachmentArray();
29 29 void beginAddAttachment(JSON);
30 30 void endAddAttachment();
31 31 void setupAddAttachmentFile();
  32 +void beginRemoveAttachmentArray(JSON);
  33 +void endRemoveAttachmentArray();
32 34 void beginCopyAttachmentsFromArray(JSON);
33 35 void endCopyAttachmentsFromArray();
34 36 void beginCopyAttachmentsFrom(JSON);
... ...
libqpdf/qpdf/auto_job_json_init.hh
... ... @@ -327,7 +327,9 @@ popHandler(); // key: replace
327 327 popHandler(); // array: .addAttachment[]
328 328 popHandler(); // key: addAttachment
329 329 pushKey("removeAttachment");
  330 +beginArray(bindJSON(&Handlers::beginRemoveAttachmentArray), bindBare(&Handlers::endRemoveAttachmentArray)); // .removeAttachment[]
330 331 addParameter([this](std::string const& p) { c_main->removeAttachment(p); });
  332 +popHandler(); // array: .removeAttachment[]
331 333 popHandler(); // key: removeAttachment
332 334 pushKey("copyAttachmentsFrom");
333 335 beginArray(bindJSON(&Handlers::beginCopyAttachmentsFromArray), bindBare(&Handlers::endCopyAttachmentsFromArray)); // .copyAttachmentsFrom[]
... ...
libqpdf/qpdf/auto_job_schema.hh
... ... @@ -111,7 +111,9 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({
111 111 "replace": "replace attachment with same key"
112 112 }
113 113 ],
114   - "removeAttachment": "remove an embedded file",
  114 + "removeAttachment": [
  115 + "remove an embedded file"
  116 + ],
115 117 "copyAttachmentsFrom": [
116 118 {
117 119 "file": "file to copy attachments from",
... ...
qpdf/qtest/qpdf.test
... ... @@ -723,7 +723,7 @@ $td-&gt;runtest(&quot;check overlay with no resources output&quot;,
723 723 show_ntests();
724 724 # ----------
725 725 $td->notify("--- File Attachments ---");
726   -$n_tests += 33;
  726 +$n_tests += 37;
727 727  
728 728 open(F, ">auto-txt") or die;
729 729 print F "from file";
... ... @@ -907,6 +907,25 @@ $td-&gt;runtest(&quot;check dates&quot;,
907 907 {$td->REGEXP => ".*CreationDate \\(D:\\d+.*ModDate \\(D:\\d+.*",
908 908 $td->EXIT_STATUS => 0},
909 909 $td->NORMALIZE_NEWLINES);
  910 +$td->runtest("remove multiple attachments",
  911 + {$td->COMMAND =>
  912 + "qpdf --verbose --static-id add-attachments-1.pdf a.pdf" .
  913 + " --remove-attachment=auto-1 --remove-attachment=auto-Two"},
  914 + {$td->FILE => "remove-multiple-attachments.out",
  915 + $td->EXIT_STATUS => 0},
  916 + $td->NORMALIZE_NEWLINES);
  917 +$td->runtest("check output",
  918 + {$td->FILE => "a.pdf"},
  919 + {$td->FILE => "remove-multiple-attachments.pdf"});
  920 +$td->runtest("remove multiple attachments (json)",
  921 + {$td->COMMAND =>
  922 + "qpdf --job-json-file=remove-multiple-attachments.json"},
  923 + {$td->FILE => "remove-multiple-attachments-json.out",
  924 + $td->EXIT_STATUS => 0},
  925 + $td->NORMALIZE_NEWLINES);
  926 +$td->runtest("check output",
  927 + {$td->FILE => "b.pdf"},
  928 + {$td->FILE => "remove-multiple-attachments.pdf"});
910 929  
911 930 show_ntests();
912 931 # ----------
... ...
qpdf/qtest/qpdf/remove-multiple-attachments-json.out 0 → 100644
  1 +qpdf: removed attachment auto-1
  2 +qpdf: removed attachment auto-Two
  3 +qpdf: wrote file b.pdf
... ...
qpdf/qtest/qpdf/remove-multiple-attachments.json 0 → 100644
  1 +{
  2 + "verbose": "",
  3 + "staticId": "",
  4 + "inputFile": "add-attachments-1.pdf",
  5 + "outputFile": "b.pdf",
  6 + "removeAttachment": [
  7 + "auto-1",
  8 + "auto-Two"
  9 + ]
  10 +}
... ...
qpdf/qtest/qpdf/remove-multiple-attachments.out 0 → 100644
  1 +qpdf: removed attachment auto-1
  2 +qpdf: removed attachment auto-Two
  3 +qpdf: wrote file a.pdf
... ...
qpdf/qtest/qpdf/remove-multiple-attachments.pdf 0 → 100644
No preview for this file type