Skip to content

fix(links): resolve a relative link to a local file against the document - #409

Merged
PathGao merged 1 commit into
fix/save-image-as-asset-urlsfrom
fix/local-file-links
Aug 3, 2026
Merged

fix(links): resolve a relative link to a local file against the document#409
PathGao merged 1 commit into
fix/save-image-as-asset-urlsfrom
fix/local-file-links

Conversation

@PathGao

@PathGao PathGao commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

5 / 5 of a stack. Base: #408. Related: #399 / #403.

The defect

[data](./data.csv) was handed to openUrl(anchor.href) — and anchor.href is what the DOM resolved against the webview origin, not a path on disk.

The two platforms then failed differently:

origin outcome
macOS / Linux tauri://localhost opener scope refuses it → ForbiddenUrlthe click does nothing, and since handleDocumentClick had no try/catch, an uncaught promise rejection
Windows http://tauri.localhost matches http://*the browser really opens onto a dead link

The fix

resolveLocalFileLinkPath(rawHref, currentFile) reuses resolveExportImagePath from #363 for the entire scheme / drive-letter / UNC / query-suffix decision table, and adds the two rules a link needs that an image does not:

  • //host/path is a web address — matching what the app's own getMarkdownLinkTarget already assumes, where the image resolver would read it as UNC;
  • a relative link in an unsaved buffer resolves to nothing, rather than to something relative to the process working directory.

The branch sits after the markdown-target branch and before the openUrl fallback. Both OS calls are now inside try/catch with a toast, which removes the uncaught rejection and turns the silent macOS click into a visible failure.

The file still will not open yet

open_path is refused by the opener scope for every path — see #399, fixed in #403. Without that, this PR is still a strict improvement: no silent click, no uncaught rejection, and Windows no longer hands a dead link to the browser. With it, the link works.

The test here asserts only that opener:allow-open-path is still granted; it deliberately does not assert the scope's shape, so it does not prejudge whichever scope is chosen in #399.

Tests

scripts/localFileLinks.test.ts — the resolver tests run the real function.

Module absent (true state of #408) suite fails to load
Module present, wiring reverted 3 red / 8 green
Final 11 / 11
npm run check   0 errors
npm test        469 / 469
cargo test      131 / 131

Not covered

  • The OS call itself — blocked above.
  • A link to a directory opens the folder. Reasonable, untested.
  • No existence check before openPath; a missing file surfaces as the toast.

🤖 Generated with Claude Code

@PathGao
PathGao force-pushed the fix/local-file-links branch 2 times, most recently from 328d330 to ce5af0b Compare August 2, 2026 23:11
`[data](./data.csv)` was handed to `openUrl(anchor.href)`, and
`anchor.href` is what the DOM resolved against the webview origin, not a
path on disk. The two platforms then failed differently: on macOS and
Linux the origin is `tauri://localhost`, which the opener scope refuses,
so the click did nothing and left an uncaught promise rejection; on
Windows it is `http://tauri.localhost`, which matches `http://*`, so the
browser really opened onto a dead link.

`resolveLocalFileLinkPath` reuses `resolveExportImagePath` from #363 for
the whole scheme, drive-letter, UNC and query-suffix decision table, and
adds two rules a link needs that an image does not: `//host/path` is a web
address, matching what `getMarkdownLinkTarget` already assumes, and a
relative link in an unsaved buffer resolves to nothing rather than to
something relative to the process working directory.

Both OS calls are now inside try/catch with a toast, which removes the
uncaught rejection and makes the macOS failure visible.

The file still will not open until the opener path scope is decided
(#399, #403); everything above is an improvement regardless.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@PathGao
PathGao force-pushed the fix/local-file-links branch from ce5af0b to 4b0d467 Compare August 2, 2026 23:13
@PathGao
PathGao merged commit c174d24 into master Aug 3, 2026
5 checks passed
@PathGao
PathGao deleted the fix/local-file-links branch August 3, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant