diff --git a/src/services/notes.js b/src/services/notes.js
index 646d6bc5f..ed0a02497 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -279,18 +279,15 @@ const downloadImagePromises = {};
function replaceUrl(content, url, imageNote) {
const quotedUrl = utils.quoteRegex(url);
- return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "g"), ` src="api/images/${imageNote.noteId}/${imageNote.title}"`);
+ return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "ig"), ` src="api/images/${imageNote.noteId}/${imageNote.title}"`);
}
async function downloadImages(noteId, content) {
- const re = /
]*?\ssrc=['"]([^'">]+)['"]/ig;
- let match;
-
- const origContent = content;
-
- while (match = re.exec(origContent)) {
- const url = match[1];
+ const imageRe = /
]*?\ssrc=['"]([^'">]+)['"]/ig;
+ let imageMatch;
+ while (imageMatch = imageRe.exec(content)) {
+ const url = imageMatch[1];
const inlineImageMatch = /^data:image\/[a-z]+;base64,/.exec(url);
if (inlineImageMatch) {
@@ -300,9 +297,9 @@ async function downloadImages(noteId, content) {
const imageService = require('../services/image');
const {note} = await imageService.saveImage(noteId, imageBuffer, "inline image", true);
- content = content.substr(0, match.index)
+ content = content.substr(0, imageMatch.index)
+ `