From 77800d073f84424185e3f53f4860a5df85b2af3e Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 9 Jan 2024 23:22:45 +0100 Subject: [PATCH] fix URL unescaping in improper place, #4566 --- src/services/notes.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/notes.js b/src/services/notes.js index 8da31c6a9..04f457f81 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -471,6 +471,8 @@ function findRelationMapLinks(content, foundLinks) { const imageUrlToAttachmentIdMapping = {}; async function downloadImage(noteId, imageUrl) { + const unescapedUrl = utils.unescapeHtml(imageUrl); + try { let imageBuffer; @@ -487,10 +489,10 @@ async function downloadImage(noteId, imageUrl) { }); }); } else { - imageBuffer = await request.getImage(imageUrl); + imageBuffer = await request.getImage(unescapedUrl); } - const parsedUrl = url.parse(imageUrl); + const parsedUrl = url.parse(unescapedUrl); const title = path.basename(parsedUrl.pathname); const imageService = require('../services/image'); @@ -519,7 +521,7 @@ function downloadImages(noteId, content) { let imageMatch; while (imageMatch = imageRe.exec(content)) { - let url = imageMatch[1]; + const url = imageMatch[1]; const inlineImageMatch = /^data:image\/[a-z]+;base64,/.exec(url); if (inlineImageMatch) { @@ -541,8 +543,6 @@ function downloadImages(noteId, content) { continue; } - url = utils.unescapeHtml(url); - if (url in imageUrlToAttachmentIdMapping) { const attachment = becca.getAttachment(imageUrlToAttachmentIdMapping[url]);