From acae20950fcabb3262822c978219c3cbf25b9498 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 13 Dec 2025 10:35:33 +1100 Subject: [PATCH] fix(linux): fix file explorer opening wrong directory (#4397) (#4777) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- v3/UNRELEASED_CHANGELOG.md | 1 + v3/internal/fileexplorer/fileexplorer_linux.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 1edf3ff47..67201eb5f 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -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 diff --git a/v3/internal/fileexplorer/fileexplorer_linux.go b/v3/internal/fileexplorer/fileexplorer_linux.go index f78b07ef7..cd0201dfc 100644 --- a/v3/internal/fileexplorer/fileexplorer_linux.go +++ b/v3/internal/fileexplorer/fileexplorer_linux.go @@ -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) {