Merge pull request #14250 from calixteman/14249

XFA - Encode tag names in UTF-8 when saving (fix #14249)
This commit is contained in:
Jonas Jenwald 2021-11-07 22:28:53 +01:00 committed by GitHub
commit 8064318015
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -14,7 +14,7 @@
*/
import { getInteger, getKeyword, HTMLResult } from "./utils.js";
import { shadow, warn } from "../../shared/util.js";
import { shadow, utf8StringToString, warn } from "../../shared/util.js";
import { encodeToXmlString } from "../core_utils.js";
import { NamespaceIds } from "./namespaces.js";
import { searchNode } from "./som.js";
@ -819,10 +819,12 @@ class XmlObject extends XFAObject {
buf.push(encodeToXmlString(this[$content]));
return;
}
const utf8TagName = utf8StringToString(tagName);
const prefix = this[$namespaceId] === NS_DATASETS ? "xfa:" : "";
buf.push(`<${prefix}${tagName}`);
buf.push(`<${prefix}${utf8TagName}`);
for (const [name, value] of this[_attributes].entries()) {
buf.push(` ${name}="${encodeToXmlString(value[$content])}"`);
const utf8Name = utf8StringToString(name);
buf.push(` ${utf8Name}="${encodeToXmlString(value[$content])}"`);
}
if (this[_dataValue] !== null) {
if (this[_dataValue]) {
@ -848,7 +850,7 @@ class XmlObject extends XFAObject {
child[$toString](buf);
}
}
buf.push(`</${prefix}${tagName}>`);
buf.push(`</${prefix}${utf8TagName}>`);
}
[$onChild](child) {

View File

@ -33,6 +33,7 @@ describe("Data serializer", function () {
<Units>1</Units>
<Unit_Price>250.00</Unit_Price>
<Total_Price>250.00</Total_Price>
<àé></àé>
</Detail>
<Page>2</Page>
<Detail PartNo="RRB-LB">
@ -59,6 +60,7 @@ describe("Data serializer", function () {
["Receipt.Detail[0].Units", "12&3"],
["Receipt.Detail[0].Unit_Price", "456>"],
["Receipt.Detail[0].Total_Price", "789"],
["Receipt.Detail[0].àé", "1011"],
["Receipt.Detail[1].PartNo", "foo-bar😀"],
["Receipt.Detail[1].Description", "hello world"],
]) {
@ -66,7 +68,7 @@ describe("Data serializer", function () {
}
const serialized = dataHandler.serialize(storage);
const expected = `<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><foo>bar</foo><bar>foo</bar><xfa:data><Receipt><Page>1</Page><Detail PartNo="GS001"><Description>Giant Slingshot</Description><Units>12&amp;3</Units><Unit_Price>456&gt;</Unit_Price><Total_Price>789</Total_Price></Detail><Page>2</Page><Detail PartNo="foo-bar&#x1F600;"><Description>hello world</Description><Units>5</Units><Unit_Price>12.00</Unit_Price><Total_Price>60.00</Total_Price></Detail><Sub_Total>310.00</Sub_Total><Tax>24.80</Tax><Total_Price>334.80</Total_Price></Receipt></xfa:data></xfa:datasets>`;
const expected = `<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><foo>bar</foo><bar>foo</bar><xfa:data><Receipt><Page>1</Page><Detail PartNo="GS001"><Description>Giant Slingshot</Description><Units>12&amp;3</Units><Unit_Price>456&gt;</Unit_Price><Total_Price>789</Total_Price><\xC3\xA0\xC3\xA9>1011</\xC3\xA0\xC3\xA9></Detail><Page>2</Page><Detail PartNo="foo-bar&#x1F600;"><Description>hello world</Description><Units>5</Units><Unit_Price>12.00</Unit_Price><Total_Price>60.00</Total_Price></Detail><Sub_Total>310.00</Sub_Total><Tax>24.80</Tax><Total_Price>334.80</Total_Price></Receipt></xfa:data></xfa:datasets>`;
expect(serialized).toEqual(expected);
});