From d07f02b95f86d7ddcf99655a21ee2bdc578b40dd Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 27 Nov 2023 10:15:29 +0100 Subject: [PATCH] contrary to what I believed encodeURIComponent() is available also in node.js, #4478 --- src/routes/api/clipper.js | 5 ++--- src/services/import/enex.js | 5 ++--- src/services/notes.js | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index 9a39ca797..15b8dc76d 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -154,9 +154,8 @@ function processContent(images, note, content) { const attachment = imageService.saveImageToAttachment(note.noteId, buffer, filename, true); - // We might want to replace with escape-html. For non-latin-based languages, this doesn't work well. - const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment"; - const url = `api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}`; + const encodedTitle = encodeURIComponent(attachment.title); + const url = `api/attachments/${attachment.attachmentId}/image/${encodedTitle}`; log.info(`Replacing '${imageId}' with '${url}' in note '${note.noteId}'`); diff --git a/src/services/import/enex.js b/src/services/import/enex.js index ec2a36c53..2ae57c806 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -303,9 +303,8 @@ function importEnex(taskContext, file, parentNote) { const attachment = imageService.saveImageToAttachment(noteEntity.noteId, resource.content, originalName, taskContext.data.shrinkImages); - // We might want to replace with escape-html. For non-latin-based languages, this doesn't work well. - const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment"; - const url = `api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}`; + const encodedTitle = encodeURIComponent(attachment.title); + const url = `api/attachments/${attachment.attachmentId}/image/${encodedTitle}`; const imageLink = ``; content = content.replace(mediaRegex, imageLink); diff --git a/src/services/notes.js b/src/services/notes.js index e9c7e1b76..c325bba9b 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -529,10 +529,9 @@ function downloadImages(noteId, content) { const imageService = require('../services/image'); const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, "inline image", true, true); - // We might want to replace with escape-html. For non-latin-based languages, this doesn't work well. - const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment"; + const encodedTitle = encodeURIComponent(attachment.title); - content = `${content.substr(0, imageMatch.index)}