Skip to content

fix(muya): load relative images from folders named with #, ? or % (#5302) - #5301

Merged
Jocs merged 2 commits into
developfrom
fix/5212-image-dirname-url-chars
Sep 11, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/5212-image-dirname-url-chars

Conversation

@Jocs

@Jocs Jocs commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #5302.

Summary

  • A relative-path image failed to load ("Load image failed") when the document's folder name contained # or ?, e.g. C# notes/note.md with ![](assets/image.jpg). getImageSrc joined the raw window.DIRNAME into a file:// URL, so Chromium read the rest of the path as a fragment or query. A literal %xx in the folder name was percent-decoded the same way.
  • getImageSrc now percent-encodes %, ? and # in the directory only. The markdown path is left as written: it is already URL-form (my%20image.jpg) and would otherwise be double-encoded.

Relation to #5212

Related to #5212. The steps there (![](assets/image.jpg) next to assets/image.jpg) do not reproduce on the published v0.20.0-rc.1 macOS arm64 build. Tested: launching with the file as an argument, cold start through Finder (open), opening into a running window, and folders named with spaces, CJK characters and %. The one failure found for that setup is a folder name containing # or ?, filed as #5302 and fixed here. It is not an rc regression: legacy muyajs built the URL as 'file://' + path.resolve(DIRNAME, src) too.

Not changed

  • packages/desktop/src/renderer/src/util/resolveImageSrc.ts (HTML/PDF export) and resolveLinkHref.ts build file:// URLs from DIRNAME the same way; left for a follow-up.
  • Absolute image paths keep going through the unchanged absolute branch.

Test plan

  • packages/muya/src/utils/__tests__/image.spec.ts: #, ? and %25 in the directory (the URL's path decodes back to the file, with no hash or query), and no re-encoding of the markdown path. All 4 fail before the fix and pass after.
  • packages/desktop/test/e2e/image-relative-path.spec.ts: new real-app case opening a document in C# 100%25 what?/. Fails on the unfixed build (the image never reaches .mu-image-success), passes with the fix.
  • muya unit suites for utils, inlineRenderer, selection, clipboard, editor and imageEditTool: 484 passed.
  • muya eslint + tsc --noEmit; desktop eslint + typecheck.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tn9MCAxQ8NDX7trUiCvMTH

Jocs and others added 2 commits September 11, 2026 09:16
)

getImageSrc joined the raw window.DIRNAME into a file:// URL, so a `#` or
`?` in the document's folder name started a fragment or query and the image
failed to load, and a literal `%xx` in the name was percent-decoded. Encode
those characters in the directory only: the markdown path is already
URL-form and must not be encoded twice.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tn9MCAxQ8NDX7trUiCvMTH
…and % (#5212)

Opens the real app on a document in `C# 100%25 what?/` and waits for the
image to load off disk; it times out on a build without the fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tn9MCAxQ8NDX7trUiCvMTH
@Jocs Jocs changed the title fix(muya): load relative images from folders named with #, ? or % (#5212) fix(muya): load relative images from folders named with #, ? or % (#5302) Sep 11, 2026
@github-actions

Copy link
Copy Markdown

Build artifacts for PR #5301:

Run: https://github.com/marktext/marktext/actions/runs/34550166948

Artifact Size Link
marktext-windows-arm64 279.4 MB Download
marktext-linux 637.8 MB Download
marktext-windows-x64 287.6 MB Download
marktext-macos-x64 297.6 MB Download
marktext-macos-arm64 287.3 MB Download

@Jocs
Jocs merged commit d19370f into develop Sep 11, 2026
16 checks passed
@Jocs
Jocs deleted the fix/5212-image-dirname-url-chars branch September 11, 2026 01:34
Jocs pushed a commit that referenced this pull request Sep 14, 2026
…? or % (#5320)

resolveLocalLinkHref joined the raw window.DIRNAME into a file:// URL, so a
`#` or `?` in the document's folder name started a fragment or query in the
exported HTML / PDF link, and a literal `%xx` in the name was percent-decoded.
Escape those characters in the directory only, as getImageSrc does in muya
since #5301: the markdown link is already URL-form and keeps its own fragment.
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.

[Bug] Relative images fail to load when the document's folder name contains # or ?

1 participant