Skip to content

Build your personal knowledge base with Trilium Notes

fix(web-clipper): keep `$` sequences in the URLs of images not downloaded

Elian Doran314f9a547ad8
diff --git a/apps/web-clipper/entrypoints/background/index.spec.ts b/apps/web-clipper/entrypoints/background/index.spec.ts
index 88f02ad7e6..463a3af12c 100644
--- a/apps/web-clipper/entrypoints/background/index.spec.ts
+++ b/apps/web-clipper/entrypoints/background/index.spec.ts
@@ -172,7 +172,7 @@ describe("background", () => {
title: "Page",
content: `<img src="i1"><img src="i2"><img src="i3"><img src="i4">`,
images: [
- { imageId: "i1", src: "https://example.com/blocked.png" },
+ { imageId: "i1", src: "https://example.com/blocked$&$$.png" },
{ imageId: "i2", src: "https://example.com/forbidden.png?a=1&b=\"2\"" },
{ imageId: "i3", src: "https://example.com/page.html" },
{ imageId: "i4", src: "https://example.com/ok.png" }
@@ -183,7 +183,7 @@ describe("background", () => {
expect(lastPayload()).toEqual({
title: "Page",
- content: `<img src="https://example.com/blocked.png">`
+ content: `<img src="https://example.com/blocked$&amp;$$.png">`
+ `<img src="https://example.com/forbidden.png?a=1&amp;b=&quot;2&quot;">`
+ `<img src="https://example.com/page.html"><img src="i4">`,
images: [ {
diff --git a/apps/web-clipper/entrypoints/background/index.ts b/apps/web-clipper/entrypoints/background/index.ts
index 6e9ae3942e..e6e2770350 100644
--- a/apps/web-clipper/entrypoints/background/index.ts
+++ b/apps/web-clipper/entrypoints/background/index.ts
@@ -246,7 +246,8 @@ export default defineBackground(() => {
if (await postProcessImage(image)) {
downloaded.push(image);
} else {
- payload.content = payload.content?.replaceAll(image.imageId, escapeHtml(image.src));
+ // A callback, so `$&` and `$$` in the URL are not read as replacement patterns.
+ payload.content = payload.content?.replaceAll(image.imageId, () => escapeHtml(image.src));
}
}