fix(linux): fix file explorer opening wrong directory (#4397) (#4777)

The pathToURI function was using url.PathEscape which incorrectly
escapes forward slashes (/ -> %2F). This caused file URIs like:

  /home/angaz -> file://%2Fhome%2Fangaz (broken)

File managers couldn't parse these malformed URIs correctly, causing
them to open the wrong directory (often a parent directory).

Fixed by using url.URL struct to properly construct file URIs:

  /home/angaz -> file:///home/angaz (correct)

Spaces and other special characters are still properly escaped.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Lea Anthony 2025-12-13 10:35:33 +11:00 committed by GitHub
commit acae20950f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -26,6 +26,7 @@ After processing, the content will be moved to the main changelog and this file
- Fix window menu crash on Wayland caused by appmenu-gtk-module accessing unrealized window (#4769) by @leaanthony
- Fix GTK application crash when app name contains invalid characters (spaces, parentheses, etc.) by @leaanthony
- Fix "not enough memory" error when initializing drag and drop on Windows (#4701) by @overlordtm
- Fix file explorer opening wrong directory on Linux due to incorrect URI escaping (#4397) by @leaanthony
- Fix AppImage build failure on modern Linux distributions (Arch, Fedora 39+, Ubuntu 24.04+) by auto-detecting `.relr.dyn` ELF sections and disabling stripping (#4642) by @leaanthony
<!-- Bug fixes -->

View file

@ -86,7 +86,14 @@ func pathToURI(path string) string {
if err != nil {
return path
}
return "file://" + url.PathEscape(absPath)
// Use url.URL to properly construct file URIs.
// url.PathEscape incorrectly escapes forward slashes (/ -> %2F),
// which breaks file manager path parsing.
u := &url.URL{
Scheme: "file",
Path: absPath,
}
return u.String()
}
func findDesktopFile(xdgFileName string) (string, error) {