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 #18034 from Snuffleupagus/FileSpec-filename-stripPath

[api-minor] Improve the `FileSpec` implementation
This commit is contained in:
Jonas Jenwald 2024-05-03 09:03:17 +02:00 committed by GitHub
commit 1b811ac113
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 49 additions and 58 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);

View file

@ -189,13 +189,6 @@ describe("display_utils", function () {
const url = "https://server.org/filename.pdf?foo=bar";
expect(getFilenameFromUrl(url)).toEqual("filename.pdf");
});
it("should get the filename from a relative URL, keeping the anchor", function () {
const url = "../../part1#part2.pdf";
expect(getFilenameFromUrl(url, /* onlyStripPath = */ true)).toEqual(
"part1#part2.pdf"
);
});
});
describe("getPdfFilenameFromUrl", function () {