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.
This commit is contained in:
callumalpass 2025-10-05 12:57:56 +11:00
parent 0c64c7c0e5
commit 5432757586
3 changed files with 11 additions and 13 deletions

View file

@ -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

View file

@ -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;

View file

@ -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") {