From 4b47bffcf512faad0fdb9d88959715dacbd7e02b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 6 Jan 2023 06:02:15 -0800 Subject: [PATCH] fix: images and files with cyrillic names don't import (#4654) closes #4559 --- server/queues/tasks/ImportMarkdownZipTask.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/queues/tasks/ImportMarkdownZipTask.ts b/server/queues/tasks/ImportMarkdownZipTask.ts index 966f8240e..0f549fb01 100644 --- a/server/queues/tasks/ImportMarkdownZipTask.ts +++ b/server/queues/tasks/ImportMarkdownZipTask.ts @@ -152,22 +152,20 @@ export default class ImportMarkdownZipTask extends ImportTask { // and replace them out with attachment redirect urls before continuing. for (const document of output.documents) { for (const attachment of output.attachments) { + const encodedPath = encodeURI(attachment.path); + // Pull the collection and subdirectory out of the path name, upload // folders in an export are relative to the document itself - const normalizedAttachmentPath = attachment.path.replace( + const normalizedAttachmentPath = encodedPath.replace( /(.*)uploads\//, "uploads/" ); const reference = `<<${attachment.id}>>`; document.text = document.text - .replace(new RegExp(escapeRegExp(attachment.path), "g"), reference) + .replace(new RegExp(escapeRegExp(encodedPath), "g"), reference) .replace( - new RegExp(escapeRegExp(normalizedAttachmentPath), "g"), - reference - ) - .replace( - new RegExp(escapeRegExp(`/${normalizedAttachmentPath}`), "g"), + new RegExp(`/?${escapeRegExp(normalizedAttachmentPath)}`, "g"), reference ); }