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

Merge pull request #14268 from calixteman/outline

Remove non-displayable chars from outline title (#14267)
This commit is contained in:
calixteman 2021-11-13 08:12:56 -08:00 committed by GitHub
commit 85c6dd59ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 3 deletions

View file

@ -486,3 +486,4 @@
!pr12828.pdf
!secHandler.pdf
!rc_annotation.pdf
!issue14267.pdf

BIN
test/pdfs/issue14267.pdf Normal file

Binary file not shown.

View file

@ -1102,6 +1102,19 @@ describe("api", function () {
await loadingTask.destroy();
});
it("gets outline with non-displayable chars", async function () {
const loadingTask = getDocument(buildGetDocumentParams("issue14267.pdf"));
const pdfDoc = await loadingTask.promise;
const outline = await pdfDoc.getOutline();
expect(Array.isArray(outline)).toEqual(true);
expect(outline.length).toEqual(1);
const outlineItem = outline[0];
expect(outlineItem.title).toEqual("hello\x11world");
await loadingTask.destroy();
});
it("gets non-existent permissions", async function () {
const permissions = await pdfDocument.getPermissions();
expect(permissions).toEqual(null);

View file

@ -185,6 +185,18 @@ describe("util", function () {
const str = "string\x00With\x00Null\x00Chars";
expect(removeNullCharacters(str)).toEqual("stringWithNullChars");
});
it("should modify string with non-displayable characters", function () {
const str = Array.from(Array(32).keys())
.map(x => String.fromCharCode(x) + "a")
.join("");
// \x00 is replaced by an empty string.
const expected =
"a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a";
expect(removeNullCharacters(str, /* replaceInvisible */ true)).toEqual(
expected
);
});
});
describe("ReadableStream", function () {