Skip to content

Commit

Permalink
Construct the correct field name and strip out classes when searching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
calixteman committed Sep 7, 2023
1 parent cf5a1d6 commit a8a50c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(".");
Expand Down
5 changes: 5 additions & 0 deletions src/core/xml_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
});

Expand Down

0 comments on commit a8a50c5

Please sign in to comment.