markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

fix: decode percent-encoded file URIs before path conversion

Open Jah-yee opened this issue 7 months ago • 1 comments

Good day,

This PR fixes issue #1738.

Problem

Before this change, file_uri_to_path() passed parsed.path directly into url2pathname(). That works for simple ASCII file paths, but breaks when the file URI contains percent-encoded non-ASCII characters such as Korean filenames.

For example, a URI like: file:///D:/.../%EC%A0%9C20...hwpx

was not being decoded into the original Unicode path before conversion to a Windows filesystem path, causing the generated path to become invalid and MCP failed to open the file.

Solution

Explicitly call unquote(parsed.path) first, so the percent-encoded URI path is restored to its real Unicode form before url2pathname() converts it into a local OS path.

In short:

  • before: URI path stayed percent-encoded too long
  • after: URI path is decoded first, then converted to Windows path

Changes

  • Added unquote to imports from urllib.parse
  • Decode URI path with unquote() before passing to url2pathname()

感谢你们的奉献,希望能提供帮助。如果我解决得有问题或有待商妥的地方,请在下面留言,我会来处理。

Warmly, RoomWithOutRoof

Jah-yee avatar Apr 13 '26 19:04 Jah-yee

+1, same pain on Windows with German and CJK filenames — url2pathname()'s legacy latin-ish decoding mangles UTF-8 percent-sequences before MarkItDown sees the real path. unquote() first, then url2pathname() restores the correct Unicode, no double-decode problem in practice.

cc @afourney — this fixes @llA1ll's #1738 and happens to touch the same line as #1573; whichever lands first, the other is a one-line rebase.

kdjkdjkdj avatar Apr 23 '26 10:04 kdjkdjkdj