From a8a50c567a4784440f23a7bfce373a6f0a4824b1 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 7 Sep 2023 15:52:58 +0200 Subject: [PATCH] Construct the correct field name and strip out classes when searching The classes were stripped out during when creating the field name but it led to a wrong name. Since class components in a path are irrelevant, they're just ignored when searching for a node in the datasets. --- src/core/annotation.js | 7 +------ src/core/xml_parser.js | 5 +++++ test/unit/api_spec.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 2e8d3580737fd..6194c96bf0eba 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -1284,12 +1284,7 @@ class Annotation { } if (loopDict.has("T")) { - const t = stringToPDFString(loopDict.get("T")); - if (!t.startsWith("#")) { - // If it starts with a # then it's a class which is not a concept for - // datasets elements (https://www.pdfa.org/norm-refs/XFA-3_3.pdf#page=96). - fieldName.unshift(t); - } + fieldName.unshift(stringToPDFString(loopDict.get("T"))); } } return fieldName.join("."); diff --git a/src/core/xml_parser.js b/src/core/xml_parser.js index a8cae401dd5f0..a1a60bf063f2a 100644 --- a/src/core/xml_parser.js +++ b/src/core/xml_parser.js @@ -354,6 +354,11 @@ class SimpleDOMNode { } const component = paths[pos]; + if (component.name.startsWith("#") && pos < paths.length - 1) { + // If it starts with a # then it's a class which is not a concept for + // datasets elements (https://www.pdfa.org/norm-refs/XFA-3_3.pdf#page=96). + return this.searchNode(paths, pos + 1); + } const stack = []; let node = this; diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index ad7bf96fa5d34..8cbd5801f67bc 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2037,6 +2037,7 @@ describe("api", function () { const value = "Hello World"; pdfDoc.annotationStorage.setValue("2055R", { value }); + pdfDoc.annotationStorage.setValue("2090R", { value }); const data = await pdfDoc.saveDocument(); await loadingTask.destroy(); @@ -2051,6 +2052,17 @@ describe("api", function () { ); expect(surName.nodeValue).toEqual(value); + // The path for the date is: + // PPTC_153[0].Page1[0].DeclerationAndSignatures[0] + // .#subform[2].currentDate[0] + // and it contains a class (i.e. #subform[2]) which is irrelevant in the + // context of datasets (it's more a template concept). + const date = getNamedNodeInXML( + datasets.node, + "xfa:data.PPTC_153.Page1.DeclerationAndSignatures.currentDate.#text" + ); + expect(date.nodeValue).toEqual(value); + await loadingTask.destroy(); });