Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XFA - Don't bind a form node with an empty value when the data node doesn't exist #13503

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/xfa/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ class Binder {
// what we've in template.
match = new XmlObject(dataNode[$namespaceId], child.name);
dataNode[$appendChild](match);

// Don't bind the value in newly created node because it's empty.
this._bindElement(child, match);
continue;
}
match = [match];
}
Expand Down
60 changes: 60 additions & 0 deletions test/unit/xfa_parser_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,66 @@ describe("XFAParser", function () {
).toBe("xyz");
});

it("should make a basic binding and create a non-existing node", function () {
const xml = `
<?xml version="1.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
<template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
<subform name="A" mergeMode="matchTemplate">
<subform name="B">
<field name="C">
</field>
<field name="D">
<value>
<text>foobar</text>
</value>
</field>
</subform>
</subform>
</template>
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<A>
</A>
</xfa:data>
</xfa:datasets>
</xdp:xdp>
`;
const root = new XFAParser().parse(xml);
const binder = new Binder(root);
const form = binder.bind();
const data = binder.getData();

expect(
searchNode(form, form, "A.B.D.value.text")[0][$dump]().$content
).toBe("foobar");

const expected = {
$name: "A",
attributes: {},
children: [
{
$name: "B",
attributes: {},
children: [
{
$name: "C",
attributes: {},
children: [],
},
{
$name: "D",
attributes: {},
children: [],
},
],
},
],
};

expect(searchNode(data, data, "A")[0][$dump]()).toEqual(expected);
});

it("should make another basic binding", function () {
const xml = `
<?xml version="1.0"?>
Expand Down