Skip to content

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

Description

@Jocs

Description

A relative-path image (![](assets/image.jpg)) shows "Load image failed" when the document's folder name contains # or ?, for example C# notes/note.md. The same document in a folder without those characters renders the image.

getImageSrc (packages/muya/src/utils/image.ts) resolves a relative image path against window.DIRNAME and puts the raw directory into a file:// URL. Chromium reads everything after # as a fragment and everything after ? as a query, so it requests a file that doesn't exist. A literal % followed by two hex digits in a folder name is percent-decoded the same way: getImageSrc turns a folder named 50%25 off into a URL for 50% off.

This is not new in 0.20: legacy muyajs built the URL as 'file://' + path.resolve(DIRNAME, src) too.

Measured on the published v0.20.0-rc.1 macOS arm64 build, opening note.md that contains ![](assets/image.jpg) next to assets/image.jpg (a real JPEG):

Document folder Image
fixture/ loads
with space/ loads
中文 目录/ loads
100% done/ loads
C# notes/ Load image failed
what? notes/ Load image failed

This issue covers images in the editor. HTML/PDF export (packages/desktop/src/renderer/src/util/resolveImageSrc.ts) and local link resolution (resolveLinkHref.ts) join DIRNAME into file:// URLs the same way; that is not verified in the app and not covered here.

Found while investigating #5212, whose own steps don't reproduce.

Steps to Reproduce

  1. Create a folder named C# notes with an assets subfolder, and save any JPEG in it as assets/image.jpg.
  2. In C# notes, create note.md containing ![](assets/image.jpg).
  3. Open note.md in MarkText.

Expected Behavior

The image renders, as it does when the folder is named notes.

Actual Behavior

The image placeholder shows "Load image failed".

Operating System

macOS

MarkText Version

0.20.0-rc.1 (also develop @ 3ed697b8)

OS Version

macOS 27.0

Reproducibility

  • I can reliably reproduce this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions