1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Support UTF-16 little-endian strings in the stringToPDFString helper function (bug 1593902)

The bug report seem to suggest that we don't support UTF-16 strings with a BOM (byte order mark), which we *actually* do as evident by both the code and a unit-test.
The issue at play here is rather that we previously only supported big-endian UTF-16 BOM, and the `Title` string in the PDF document is using a *little-endian* UTF-16 BOM instead.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1593902
This commit is contained in:
Jonas Jenwald 2019-11-05 11:52:30 +01:00
parent de77d6686c
commit 80342e2fdc
2 changed files with 16 additions and 1 deletions

View file

@ -752,6 +752,12 @@ function stringToPDFString(str) {
strBuf.push(String.fromCharCode(
(str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
}
} else if (str[0] === '\xFF' && str[1] === '\xFE') {
// UTF16LE BOM
for (let i = 2; i < length; i += 2) {
strBuf.push(String.fromCharCode(
(str.charCodeAt(i + 1) << 8) | str.charCodeAt(i)));
}
} else {
for (let i = 0; i < length; ++i) {
const code = PDFStringTranslateTable[str.charCodeAt(i)];