From 13ae6d493a1129b6958b10be6ab1e557485c0bbc Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 7 Nov 2021 21:41:37 +0100 Subject: [PATCH] XFA - Encode tag names in UTF-8 when saving (fix #14249) --- src/core/xfa/xfa_object.js | 10 ++++++---- test/unit/xfa_serialize_data_spec.js | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/xfa/xfa_object.js b/src/core/xfa/xfa_object.js index b1808fb0f..e22c4435c 100644 --- a/src/core/xfa/xfa_object.js +++ b/src/core/xfa/xfa_object.js @@ -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(``); + buf.push(``); } [$onChild](child) { diff --git a/test/unit/xfa_serialize_data_spec.js b/test/unit/xfa_serialize_data_spec.js index 6e29cd006..faeaf4c84 100644 --- a/test/unit/xfa_serialize_data_spec.js +++ b/test/unit/xfa_serialize_data_spec.js @@ -33,6 +33,7 @@ describe("Data serializer", function () { 1 250.00 250.00 + <àé> 2 @@ -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 = `barfoo1Giant Slingshot12&3456>7892hello world512.0060.00310.0024.80334.80`; + const expected = `barfoo1Giant Slingshot12&3456>789<\xC3\xA0\xC3\xA9>10112hello world512.0060.00310.0024.80334.80`; expect(serialized).toEqual(expected); });