mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Support FileAttachments with hash-signs in the filename (issue 15729)
The reason for the issue is that we use the generic `getFilenameFromUrl` helper function, which was originally intended for regular URLs. For the filenames we're dealing with in FileAttachments, we really only want to strip the path when one exists[1]. --- [1] See [bug 1230933](https://bugzilla.mozilla.org/show_bug.cgi?id=1230933) for an example of such a case.
This commit is contained in:
parent
a0db81723b
commit
0ba242ea4a
4 changed files with 20 additions and 9 deletions
|
@ -2496,7 +2496,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
|
|||
super(parameters, { isRenderable: true });
|
||||
|
||||
const { filename, content } = this.data.file;
|
||||
this.filename = getFilenameFromUrl(filename);
|
||||
this.filename = getFilenameFromUrl(filename, /* onlyStripPath = */ true);
|
||||
this.content = content;
|
||||
|
||||
this.linkService.eventBus?.dispatch("fileattachmentannotation", {
|
||||
|
|
|
@ -334,15 +334,16 @@ function isPdfFile(filename) {
|
|||
/**
|
||||
* Gets the filename from a given URL.
|
||||
* @param {string} url
|
||||
* @param {boolean} [onlyStripPath]
|
||||
* @returns {string}
|
||||
*/
|
||||
function getFilenameFromUrl(url) {
|
||||
const anchor = url.indexOf("#");
|
||||
const query = url.indexOf("?");
|
||||
const end = Math.min(
|
||||
anchor > 0 ? anchor : url.length,
|
||||
query > 0 ? query : url.length
|
||||
);
|
||||
function getFilenameFromUrl(url, onlyStripPath = false) {
|
||||
let end = url.length;
|
||||
if (!onlyStripPath) {
|
||||
const anchor = url.indexOf("#");
|
||||
const query = url.indexOf("?");
|
||||
end = Math.min(anchor > 0 ? anchor : end, query > 0 ? query : end);
|
||||
}
|
||||
return url.substring(url.lastIndexOf("/", end) + 1, end);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue