diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-04-24 16:08:32 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-04-24 16:08:32 +0200 |
commit | 08ba21cf4935fec39d3454714c03d36ff6a6b836 (patch) | |
tree | 4eda1a94c86f3e76e9d4a1d43fa46d57004f05e9 /qpdf | |
parent | 4be2f3604939de8589dd2206fdf3d1a85033f171 (diff) | |
download | qpdf-08ba21cf4935fec39d3454714c03d36ff6a6b836.tar.zst |
Fix some bugs around null values in dictionaries
Make it so that a key with a null value is always treated as not being
present. This was inconsistent before.
Diffstat (limited to 'qpdf')
-rw-r--r-- | qpdf/qtest/qpdf.test | 11 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/bad34-recover.out | 2 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/good11.out | 4 | ||||
-rw-r--r-- | qpdf/test_driver.cc | 24 |
4 files changed, 36 insertions, 5 deletions
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 36f843f7..5bf6be76 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -1421,6 +1421,17 @@ foreach (my $i = 1; $i <= 3; ++$i) show_ntests(); # ---------- +$td->notify("--- Dictionary keys ---"); +$n_tests += 1; + +$td->runtest("dictionary keys", + {$td->COMMAND => "test_driver 87 - -"}, + {$td->STRING => "test 87 done\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +show_ntests(); +# ---------- $td->notify("--- Stream data ---"); $n_tests += 2; diff --git a/qpdf/qtest/qpdf/bad34-recover.out b/qpdf/qtest/qpdf/bad34-recover.out index 4cee51be..def6c378 100644 --- a/qpdf/qtest/qpdf/bad34-recover.out +++ b/qpdf/qtest/qpdf/bad34-recover.out @@ -2,7 +2,7 @@ WARNING: bad34.pdf: file is damaged WARNING: bad34.pdf (object 4 0, offset 322): expected n n obj WARNING: bad34.pdf: Attempting to reconstruct cross-reference table /QTest is indirect and has type stream (10) -/QTest is a stream. Dictionary: << /Length 44 /Quack 9 0 R >> +/QTest is a stream. Dictionary: << /Length 44 >> Raw stream data: BT /F1 24 Tf diff --git a/qpdf/qtest/qpdf/good11.out b/qpdf/qtest/qpdf/good11.out index 2079096a..06358d49 100644 --- a/qpdf/qtest/qpdf/good11.out +++ b/qpdf/qtest/qpdf/good11.out @@ -1,6 +1,6 @@ /QTest is direct and has type dictionary (9) /QTest is a dictionary /a is direct -unparse: << /a (a) /b 8 0 R >> -unparseResolved: << /a (a) /b 8 0 R >> +unparse: << /a (a) >> +unparseResolved: << /a (a) >> test 1 done diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 0245e0f5..ead0b484 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -3158,6 +3158,26 @@ test_86(QPDF& pdf, char const* arg2) assert(h.getUTF8Value() == utf8_val); } +static void +test_87(QPDF& pdf, char const* arg2) +{ + // Explicitly demonstrate null dictionary values being the same as + // missing keys. + auto dict = "<< /A 1 /B null >>"_qpdf; + assert(dict.unparse() == "<< /A 1 >>"); + assert(dict.getKeys() == std::set<std::string>({"/A"})); + dict.replaceKey("/A", QPDFObjectHandle::newNull()); + assert(dict.unparse() == "<< >>"); + assert(dict.getKeys() == std::set<std::string>()); + dict = QPDFObjectHandle::newDictionary({ + {"/A", "2"_qpdf}, + {"/B", QPDFObjectHandle::newNull()}, + }); + assert(dict.unparse() == "<< /A 2 >>"); + assert(dict.getKeys() == std::set<std::string>({"/A"})); + assert(dict.getJSON().unparse() == "{\n \"/A\": 2\n}"); +} + void runtest(int n, char const* filename1, char const* arg2) { @@ -3165,7 +3185,7 @@ runtest(int n, char const* filename1, char const* arg2) // the test suite to see how the test is invoked to find the file // that the test is supposed to operate on. - std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86}; + std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87}; if (n == 0) { // Throw in some random test cases that don't fit anywhere @@ -3259,7 +3279,7 @@ runtest(int n, char const* filename1, char const* arg2) {72, test_72}, {73, test_73}, {74, test_74}, {75, test_75}, {76, test_76}, {77, test_77}, {78, test_78}, {79, test_79}, {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83}, - {84, test_84}, {85, test_85}, {86, test_86}, + {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, }; auto fn = test_functions.find(n); |