From 2ac099bd39d135566764029377ee8be137ab6c16 Mon Sep 17 00:00:00 2001 From: m-holger Date: Wed, 3 Dec 2025 17:04:53 +0000 Subject: [PATCH] Refactor `AcroForm::traverseField` to improve field handling logic: streamline checks, replace manual key access with `FormNode` methods, and enhance maintainability. --- libqpdf/QPDFAcroFormDocumentHelper.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 0c71ae3..c0d0207 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -432,7 +432,11 @@ AcroForm::traverseField(QPDFObjectHandle field, QPDFObjectHandle const& parent, annotation_to_field_[og] = QPDFFormFieldObjectHelper(our_field); } - if (is_field && depth != 0 && field["/Parent"] != parent) { + if (!is_field) { + return true; + } + + if (depth != 0 && field["/Parent"] != parent) { for (auto const& kid: Array(field["/Parent"]["/Kids"])) { if (kid == field) { field.warn("while traversing /AcroForm found field with two parents"); @@ -449,14 +453,13 @@ AcroForm::traverseField(QPDFObjectHandle field, QPDFObjectHandle const& parent, field.replaceKey("/Parent", parent); } - if (is_field && field.hasKey("/T")) { - QPDFFormFieldObjectHelper foh(field); - std::string name = foh.getFullyQualifiedName(); + if (node.T()) { auto old = fields_.find(og); if (old != fields_.end() && !old->second.name.empty()) { // We might be updating after a name change, so remove any old information name_to_fields_[old->second.name].erase(og); } + std::string name = node.fully_qualified_name(); fields_[og].name = name; name_to_fields_[name].insert(og); } -- libgit2 0.21.4