Skip to content

Commit d07f02b

Browse files
committed
contrary to what I believed encodeURIComponent() is available also in node.js, #4478
1 parent ad74952 commit d07f02b

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/routes/api/clipper.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ function processContent(images, note, content) {
154154

155155
const attachment = imageService.saveImageToAttachment(note.noteId, buffer, filename, true);
156156

157-
// We might want to replace with escape-html. For non-latin-based languages, this doesn't work well.
158-
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment";
159-
const url = `api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}`;
157+
const encodedTitle = encodeURIComponent(attachment.title);
158+
const url = `api/attachments/${attachment.attachmentId}/image/${encodedTitle}`;
160159

161160
log.info(`Replacing '${imageId}' with '${url}' in note '${note.noteId}'`);
162161

src/services/import/enex.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ function importEnex(taskContext, file, parentNote) {
303303

304304
const attachment = imageService.saveImageToAttachment(noteEntity.noteId, resource.content, originalName, taskContext.data.shrinkImages);
305305

306-
// We might want to replace with escape-html. For non-latin-based languages, this doesn't work well.
307-
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment";
308-
const url = `api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}`;
306+
const encodedTitle = encodeURIComponent(attachment.title);
307+
const url = `api/attachments/${attachment.attachmentId}/image/${encodedTitle}`;
309308
const imageLink = `<img src="${url}">`;
310309

311310
content = content.replace(mediaRegex, imageLink);

src/services/notes.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,9 @@ function downloadImages(noteId, content) {
529529
const imageService = require('../services/image');
530530
const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, "inline image", true, true);
531531

532-
// We might want to replace with escape-html. For non-latin-based languages, this doesn't work well.
533-
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment";
532+
const encodedTitle = encodeURIComponent(attachment.title);
534533

535-
content = `${content.substr(0, imageMatch.index)}<img src="api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}"${content.substr(imageMatch.index + imageMatch[0].length)}`;
534+
content = `${content.substr(0, imageMatch.index)}<img src="api/attachments/${attachment.attachmentId}/image/${encodedTitle}"${content.substr(imageMatch.index + imageMatch[0].length)}`;
536535
}
537536
else if (!url.includes('api/images/') && !/api\/attachments\/.+\/image\/?.*/.test(url)
538537
// this is an exception for the web clipper's "imageId"

0 commit comments

Comments
 (0)