From 710d2e54f0762b7702640766d33b7e0977ba69de Mon Sep 17 00:00:00 2001 From: m-holger Date: Wed, 26 Jan 2022 01:28:53 +0000 Subject: [PATCH] Allow testing for subtype without specifying type in isDictionaryOfType etc Accept empty string as type parameter in QPDFObjectHandle::isDictionaryOfType and isStreamOfType to allow for dictionaries with optional type. --- libqpdf/QPDFObjectHandle.cc | 12 +++--------- qpdf/qpdf-ctest.c | 2 +- qpdf/test_driver.cc | 5 +++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index f2c77dca..2713eb95 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -507,15 +507,9 @@ bool QPDFObjectHandle::isDictionaryOfType(std::string const& type, std::string const& subtype) { - if (isDictionary() && getKey("/Type").isNameAndEquals(type)) - { - return (subtype == "") || - (hasKey("/Subtype") && getKey("/Subtype").isNameAndEquals(subtype)); - } - else - { - return false; - } + return isDictionary() && + (type.empty() || getKey("/Type").isNameAndEquals(type)) && + (subtype.empty() || getKey("/Subtype").isNameAndEquals(subtype)); } bool diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c index 37225a22..e9a7f1a8 100644 --- a/qpdf/qpdf-ctest.c +++ b/qpdf/qpdf-ctest.c @@ -724,7 +724,7 @@ static void test25(char const* infile, assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/Marvin")); assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test2", "")); assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/M")); - assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "", "")); + assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "", "")); qpdf_oh new_array = qpdf_oh_new_array(qpdf); qpdf_oh_replace_or_remove_key( qpdf, new_dict, "/A", qpdf_oh_new_null(qpdf)); diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 28f42643..796d51fb 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -3110,11 +3110,12 @@ static void test_82(QPDF& pdf, char const* arg2) assert(dict.isDictionaryOfType( "/Test", "")); assert(dict.isDictionaryOfType("/Test")); assert(dict.isDictionaryOfType("/Test", "/Marvin")); + assert(dict.isDictionaryOfType("", "/Marvin")); + assert(dict.isDictionaryOfType("", "")); assert(! dict.isDictionaryOfType("/Test2", "")); assert(! dict.isDictionaryOfType("/Test2", "/Marvin")); assert(! dict.isDictionaryOfType("/Test", "/M")); - assert(! dict.isDictionaryOfType("", "/Marvin")); - assert(! dict.isDictionaryOfType("", "")); + assert(! name.isDictionaryOfType("", "")); dict = QPDFObjectHandle::parse("<>"); assert(! dict.isDictionaryOfType("/Test")); dict = QPDFObjectHandle::parse("<>");