fix: decode percent-encoded file URIs before path conversion
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
unquoteto imports fromurllib.parse - Decode URI path with
unquote()before passing tourl2pathname()
感谢你们的奉献,希望能提供帮助。如果我解决得有问题或有待商妥的地方,请在下面留言,我会来处理。
Warmly, RoomWithOutRoof
+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.