From 78266ae5d0bf8052fd37700932905856afa7fb19 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 | 14 +++++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 2e8d3580737fdf..6194c96bf0eba4 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 a8cae401dd5f0b..a1a60bf063f2ac 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 ad7bf96fa5d348..81d4a1008073f2 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2027,7 +2027,7 @@ describe("api", function () { await loadingTask.destroy(); }); - it("write a value in an annotation, save the pdf and check the value in xfa datasets (1)", async function () { + fit("write a value in an annotation, save the pdf and check the value in xfa datasets (1)", async function () { if (isNodeJS) { pending("Linked test-cases are not supported in Node.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(); });