Commit 8eca9d8fd988d6834f3d59554277ff1d9f05d8c9
Committed by
Jay Berkenbilt
1 parent
07db3200
Fix QPDFObjectHandle::isOrHasName
Ensure isOrHasName returns true if object is an array and the name is present anywhere in the array.
Showing
2 changed files
with
24 additions
and
3 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -1055,9 +1055,21 @@ QPDFObjectHandle::getDictAsMap() |
| 1055 | 1055 | bool |
| 1056 | 1056 | QPDFObjectHandle::isOrHasName(std::string const& value) |
| 1057 | 1057 | { |
| 1058 | - return isNameAndEquals(value) || | |
| 1059 | - (isArray() && (getArrayNItems() > 0) && | |
| 1060 | - getArrayItem(0).isNameAndEquals(value)); | |
| 1058 | + if (isNameAndEquals(value)) | |
| 1059 | + { | |
| 1060 | + return true; | |
| 1061 | + } | |
| 1062 | + else if (isArray()) | |
| 1063 | + { | |
| 1064 | + for (auto& item: aitems()) | |
| 1065 | + { | |
| 1066 | + if (item.isNameAndEquals(value)) | |
| 1067 | + { | |
| 1068 | + return true; | |
| 1069 | + } | |
| 1070 | + } | |
| 1071 | + } | |
| 1072 | + return false; | |
| 1061 | 1073 | } |
| 1062 | 1074 | |
| 1063 | 1075 | void | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -3128,6 +3128,15 @@ static void test_82(QPDF& pdf, char const* arg2) |
| 3128 | 3128 | assert(stream.isStreamOfType("/ObjStm")); |
| 3129 | 3129 | assert(! stream.isStreamOfType("/Test")); |
| 3130 | 3130 | assert(! pdf.getObjectByID(2,0).isStreamOfType("/Pages")); |
| 3131 | + auto array = QPDFObjectHandle::parse("[/Blah /Blaah /Blaaah]"); | |
| 3132 | + assert(array.isOrHasName("/Blah")); | |
| 3133 | + assert(array.isOrHasName("/Blaaah")); | |
| 3134 | + assert(! array.isOrHasName("/Blaaaah")); | |
| 3135 | + assert(array.getArrayItem(0).isOrHasName("/Blah")); | |
| 3136 | + assert(! array.getArrayItem(1).isOrHasName("/Blah")); | |
| 3137 | + array = QPDFObjectHandle::parse("[]"); | |
| 3138 | + assert(! array.isOrHasName("/Blah")); | |
| 3139 | + assert(! str.isOrHasName("/Marvin")); | |
| 3131 | 3140 | } |
| 3132 | 3141 | |
| 3133 | 3142 | void runtest(int n, char const* filename1, char const* arg2) | ... | ... |