Merge pull request #16915 from calixteman/issue16914

Construct the correct field name and strip out classes when searching
This commit is contained in:
calixteman 2023-09-07 16:46:33 +02:00 committed by GitHub
commit 3e32d87be7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View File

@ -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(".");

View File

@ -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;

View File

@ -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();
});