Skip to content

Decode non-ASCII values found in the xfa:datasets (PR 14735 follow-up) #14738

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

Merged
merged 1 commit into from
Apr 1, 2022
Merged
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
14 changes: 12 additions & 2 deletions src/core/dataset_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down