Fix encoding of inline content (#1186)

Inline content with the file containing e.g. a `:` cannot be displayed
as the file name is set as the img src, and the browser treats the part
before the : as the protocol, instead of as a file name.

This change encodes the file name so `:` becomes `%3A`, fixing the
issue.

Fixes #1182.
main
István Szekeres 2025-01-07 18:56:45 +00:00 committed by GitHub
parent f801fd263b
commit fdd3d1b650
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 4 deletions

View File

@ -56,15 +56,17 @@ class InlineContentWidget extends WidgetType {
return div;
}
const url = encodeURIComponent(this.url)
if (mimeType.startsWith("image/")) {
const img = document.createElement("img");
img.src = this.url;
img.src = url;
img.alt = this.title;
this.setDim(img, "load");
div.appendChild(img);
} else if (mimeType.startsWith("video/")) {
const video = document.createElement("video");
video.src = this.url;
video.src = url;
video.title = this.title;
video.controls = true;
video.autoplay = false;
@ -72,7 +74,7 @@ class InlineContentWidget extends WidgetType {
div.appendChild(video);
} else if (mimeType.startsWith("audio/")) {
const audio = document.createElement("audio");
audio.src = this.url;
audio.src = url;
audio.title = this.title;
audio.controls = true;
audio.autoplay = false;
@ -81,7 +83,7 @@ class InlineContentWidget extends WidgetType {
} else if (mimeType === "application/pdf") {
const embed = document.createElement("object");
embed.type = mimeType;
embed.data = this.url;
embed.data = url;
embed.style.width = "100%";
embed.style.height = "20em";
this.setDim(embed, "load");