Merge pull request #15730 from Snuffleupagus/issue-15729
Support FileAttachments with hash-signs in the filename (issue 15729)
This commit is contained in:
commit
73c268dc1c
@ -2496,7 +2496,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
|
|||||||
super(parameters, { isRenderable: true });
|
super(parameters, { isRenderable: true });
|
||||||
|
|
||||||
const { filename, content } = this.data.file;
|
const { filename, content } = this.data.file;
|
||||||
this.filename = getFilenameFromUrl(filename);
|
this.filename = getFilenameFromUrl(filename, /* onlyStripPath = */ true);
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
|
||||||
this.linkService.eventBus?.dispatch("fileattachmentannotation", {
|
this.linkService.eventBus?.dispatch("fileattachmentannotation", {
|
||||||
|
@ -334,16 +334,14 @@ function isPdfFile(filename) {
|
|||||||
/**
|
/**
|
||||||
* Gets the filename from a given URL.
|
* Gets the filename from a given URL.
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
|
* @param {boolean} [onlyStripPath]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function getFilenameFromUrl(url) {
|
function getFilenameFromUrl(url, onlyStripPath = false) {
|
||||||
const anchor = url.indexOf("#");
|
if (!onlyStripPath) {
|
||||||
const query = url.indexOf("?");
|
[url] = url.split(/[#?]/, 1);
|
||||||
const end = Math.min(
|
}
|
||||||
anchor > 0 ? anchor : url.length,
|
return url.substring(url.lastIndexOf("/") + 1);
|
||||||
query > 0 ? query : url.length
|
|
||||||
);
|
|
||||||
return url.substring(url.lastIndexOf("/", end) + 1, end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,6 +190,13 @@ describe("display_utils", function () {
|
|||||||
const url = "https://server.org/filename.pdf?foo=bar";
|
const url = "https://server.org/filename.pdf?foo=bar";
|
||||||
expect(getFilenameFromUrl(url)).toEqual("filename.pdf");
|
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 () {
|
describe("getPdfFilenameFromUrl", function () {
|
||||||
|
@ -118,7 +118,10 @@ class PDFAttachmentViewer extends BaseTreeViewer {
|
|||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
const item = attachments[name];
|
const item = attachments[name];
|
||||||
const content = item.content,
|
const content = item.content,
|
||||||
filename = getFilenameFromUrl(item.filename);
|
filename = getFilenameFromUrl(
|
||||||
|
item.filename,
|
||||||
|
/* onlyStripPath = */ true
|
||||||
|
);
|
||||||
|
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.className = "treeItem";
|
div.className = "treeItem";
|
||||||
|
Loading…
Reference in New Issue
Block a user