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

[api-minor] Improve the FileSpec implementation

- Check that the `filename` is actually a string, before parsing it further.
 - Use proper "shadowing" in the `filename` getter.
 - Add a bit more validation of the data in `pickPlatformItem`.
 - Last, but not least, return both the original `filename` and the (path stripped) variant needed in the display-layer and viewer.
This commit is contained in:
Jonas Jenwald 2024-05-01 12:28:33 +02:00
parent 16dbf5dcfd
commit 2b69fb76ac
6 changed files with 47 additions and 46 deletions

View file

@ -4033,9 +4033,12 @@ describe("annotation", function () {
idFactoryMock
);
expect(data.annotationType).toEqual(AnnotationType.FILEATTACHMENT);
expect(data.file.filename).toEqual("Test.txt");
expect(data.file.content).toEqual(stringToBytes("Test attachment"));
expect(data.file.description).toEqual("abc");
expect(data.file).toEqual({
rawFilename: "Test.txt",
filename: "Test.txt",
content: stringToBytes("Test attachment"),
description: "abc",
});
});
});

View file

@ -1475,12 +1475,12 @@ describe("api", function () {
const pdfDoc = await loadingTask.promise;
const attachments = await pdfDoc.getAttachments();
const { filename, content, description } = attachments["foo.txt"];
expect(filename).toEqual("foo.txt");
expect(content).toEqual(
new Uint8Array([98, 97, 114, 32, 98, 97, 122, 32, 10])
);
expect(description).toEqual("");
expect(attachments["foo.txt"]).toEqual({
rawFilename: "foo.txt",
filename: "foo.txt",
content: new Uint8Array([98, 97, 114, 32, 98, 97, 122, 32, 10]),
description: "",
});
await loadingTask.destroy();
});
@ -1490,7 +1490,9 @@ describe("api", function () {
const pdfDoc = await loadingTask.promise;
const attachments = await pdfDoc.getAttachments();
const { filename, content, description } = attachments["empty.pdf"];
const { rawFilename, filename, content, description } =
attachments["empty.pdf"];
expect(rawFilename).toEqual("Empty page.pdf");
expect(filename).toEqual("Empty page.pdf");
expect(content instanceof Uint8Array).toEqual(true);
expect(content.length).toEqual(2357);