From a0c0bd530241032211deaad420ea6d58d5e16f7b Mon Sep 17 00:00:00 2001 From: bingryan Date: Sat, 3 Jan 2026 09:09:23 +0800 Subject: [PATCH] fix: resolve attachment export inconsistencies (#108) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Unify filename encoding between tryCopyImage and tryCopyMarkdownByRead (both now use encodeURI(fileName) when fileNameEncode is off) - Add check to skip copying when source and target paths are identical (prevents file corruption for attachments already in output folder) Fixes issues where: - Some attachments had encoded names while others didn't - Attachment files were corrupted during export - Attachments were placed in different folders inconsistently 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index a8d958f..7799af1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -355,7 +355,7 @@ export async function tryCopyImage( const fileName = path.parse(path.basename(imageLink)).name; const imageLinkMd5 = plugin.settings.fileNameEncode ? md5(imageLink) - : fileName; + : encodeURI(fileName); const imageExt = path.extname(imageLink); const ifile = plugin.app.metadataCache.getFirstLinkpathDest( imageLink, @@ -394,6 +394,12 @@ export async function tryCopyImage( ) .replace(/\\/g, "/"); + // Skip if source and target are the same (prevents file corruption) + // This can happen when an attachment is already in the output folder + if (filePath === targetPath) { + continue; + } + try { if (!fileExists(targetPath)) { if (