Skip to content

[v3] Normalize Windows paths on system Dialogs invocations #4188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/content/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed initially-hidden menu items by [@IanVS](https://github.com/IanVS) in [#4116](https://github.com/wailsapp/wails/pull/4116)
- Fixed assetFileServer not serving `.html` files when non-extension request when `[request]` doesn't exist but `[request].html` does
- Fixed icon generation paths by [@robin-samuel](https://github.com/robin-samuel) in [#4125](https://github.com/wailsapp/wails/pull/4125)
- Fixed Dialogs runtime function returning escaped paths on Windows by [TheGB0077](https://github.com/TheGB0077) in [#4188](https://github.com/wailsapp/wails/pull/4188)

### Changed

Expand Down
17 changes: 15 additions & 2 deletions v3/pkg/application/dialogs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,20 @@ func showCfdDialog(newDlg func() (cfd.Dialog, error), isMultiSelect bool) (any,
}()

if multi, _ := dlg.(cfd.OpenMultipleFilesDialog); multi != nil && isMultiSelect {
return multi.ShowAndGetResults()
paths, err := multi.ShowAndGetResults()
if err != nil {
return nil, err
}

for i, path := range paths {
paths[i] = filepath.Clean(path)
}
return paths, nil
}

path, err := dlg.ShowAndGetResult()
if err != nil {
return nil, err
}
return dlg.ShowAndGetResult()
return filepath.Clean(path), nil
}
57 changes: 57 additions & 0 deletions v3/pkg/application/dialogs_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//go:build windows

package application_test

import (
"path/filepath"
"testing"

"github.com/matryer/is"
)

func TestCleanPath(t *testing.T) {
i := is.New(t)
tests := []struct {
name string
inputPath string
expected string
}{
{
name: "path with double separators",
inputPath: `C:\\temp\\folder`,
expected: `C:\temp\folder`,
},
{
name: "path with forward slashes",
inputPath: `C://temp//folder`,
expected: `C:\temp\folder`,
},
{
name: "path with trailing separator",
inputPath: `C:\\temp\\folder\\`,
expected: `C:\temp\folder`,
},
{
name: "path with escaped tab character",
inputPath: `C:\\Users\\test\\tab.txt`,
expected: `C:\Users\test\tab.txt`,
},
{
name: "newline character",
inputPath: `C:\\Users\\test\\newline\\n.txt`,
expected: `C:\Users\test\newline\n.txt`,
},
{
name: "UNC path with multiple separators",
inputPath: `\\\\\\\\host\\share\\test.txt`,
expected: `\\\\host\share\test.txt`,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cleaned := filepath.Clean(tt.inputPath)
i.Equal(cleaned, tt.expected)
})
}
}
Loading