From 13b067fb3f45c01f16cae688bc12e4c619ee10b6 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 17 Aug 2023 22:46:40 +0200 Subject: [PATCH] fix: Document importer only replaces first base64 encoded image when there are multiple identical images in a document closes #5653 --- server/commands/documentImporter.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/commands/documentImporter.ts b/server/commands/documentImporter.ts index 7af02a1f1..5e64c3793 100644 --- a/server/commands/documentImporter.ts +++ b/server/commands/documentImporter.ts @@ -1,5 +1,6 @@ import path from "path"; import emojiRegex from "emoji-regex"; +import escapeRegExp from "lodash/escapeRegExp"; import truncate from "lodash/truncate"; import mammoth from "mammoth"; import quotedPrintable from "quoted-printable"; @@ -221,7 +222,10 @@ async function documentImporter({ ip, transaction, }); - text = text.replace(uri, attachment.redirectUrl); + text = text.replace( + new RegExp(escapeRegExp(uri), "g"), + attachment.redirectUrl + ); } // It's better to truncate particularly long titles than fail the import