From 54327575861ec8ecfc3e2e75de1afc901ab133e5 Mon Sep 17 00:00:00 2001 From: callumalpass Date: Sun, 5 Oct 2025 12:57:56 +1100 Subject: [PATCH] fix: Support relative paths in inline task link replacement (#440) Remove overly aggressive path sanitization that stripped ".." from link paths, which broke relative path resolution for both wikilinks and markdown links. Obsidian's metadataCache.getFirstLinkpathDest() already handles relative paths safely, so the sanitization was unnecessary and harmful. --- docs/releases/unreleased.md | 7 +++++++ src/editor/ReadingModeTaskLinkProcessor.ts | 8 ++------ src/editor/TaskLinkOverlay.ts | 9 ++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/releases/unreleased.md b/docs/releases/unreleased.md index a495849d..5cc59490 100644 --- a/docs/releases/unreleased.md +++ b/docs/releases/unreleased.md @@ -27,6 +27,13 @@ Example: ## Fixed +- (#440) Fixed inline task replacement not working for links with relative paths + - Markdown links with relative paths like `[task](../../../GTD/tasks/task.md)` now display inline previews + - Wikilinks with relative paths now work correctly + - Removed overly aggressive path sanitization that was stripping `..` from all link paths + - Works in both Live Preview and Reading Mode + - Thanks to @minchinweb for reporting + - (#814) Fixed markdown links in projects field not being recognized on Project notes - Tasks with markdown-style project links `[text](path)` now appear in project's Subtasks section - Updated project link detection to use `parseLinkToPath` utility which handles both wikilinks and markdown links diff --git a/src/editor/ReadingModeTaskLinkProcessor.ts b/src/editor/ReadingModeTaskLinkProcessor.ts index aa769e25..ef90246d 100644 --- a/src/editor/ReadingModeTaskLinkProcessor.ts +++ b/src/editor/ReadingModeTaskLinkProcessor.ts @@ -109,13 +109,9 @@ export class ReadingModeTaskLinkProcessor { */ private resolveLinkPath(linkPath: string, sourcePath: string): string | null { try { - // Sanitize link path to prevent directory traversal - const sanitizedLinkPath = linkPath.replace(/\.\./g, "").trim(); - if (!sanitizedLinkPath) return null; - - // Use Obsidian's metadata cache to resolve the link + // Use Obsidian's metadata cache to resolve the link - it handles relative paths safely const file = this.plugin.app.metadataCache.getFirstLinkpathDest( - sanitizedLinkPath, + linkPath, sourcePath ); return file?.path || null; diff --git a/src/editor/TaskLinkOverlay.ts b/src/editor/TaskLinkOverlay.ts index 390767eb..fa434380 100644 --- a/src/editor/TaskLinkOverlay.ts +++ b/src/editor/TaskLinkOverlay.ts @@ -394,13 +394,8 @@ function resolveLinkPathSync( } try { - // Sanitize link path to prevent directory traversal - const sanitizedLinkPath = linkPath.replace(/\.\./g, "").trim(); - if (!sanitizedLinkPath) { - return null; - } - - const file = plugin.app.metadataCache.getFirstLinkpathDest(sanitizedLinkPath, sourcePath); + // Use Obsidian's API to resolve the link path - it handles relative paths safely + const file = plugin.app.metadataCache.getFirstLinkpathDest(linkPath, sourcePath); // Validate result if (!file || !file.path || typeof file.path !== "string") {