Merge pull request #14738 from Snuffleupagus/xfa-datasets-decode

Decode non-ASCII values found in the xfa:datasets (PR 14735 follow-up)
This commit is contained in:
Jonas Jenwald 2022-04-01 12:36:57 +02:00 committed by GitHub
commit 38e9a46a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,9 +13,19 @@
* limitations under the License.
*/
import { stringToUTF8String, warn } from "../shared/util.js";
import { parseXFAPath } from "./core_utils.js";
import { SimpleXMLParser } from "./xml_parser.js";
function decodeString(str) {
try {
return stringToUTF8String(str);
} catch (ex) {
warn(`UTF-8 decoding failed: "${ex}".`);
return str;
}
}
class DatasetXMLParser extends SimpleXMLParser {
constructor(options) {
super(options);
@ -60,10 +70,10 @@ class DatasetReader {
const first = node.firstChild;
if (first && first.nodeName === "value") {
return node.children.map(child => child.textContent);
return node.children.map(child => decodeString(child.textContent));
}
return node.textContent;
return decodeString(node.textContent);
}
}