Merge pull request #5449 from laurazard/backport-lowercase-windows-drive

[27.x backport] command: change drive to lowercase for wsl path
This commit is contained in:
Sebastiaan van Stijn 2024-09-18 12:16:32 +02:00 committed by GitHub
commit ddf8f23403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 15 deletions

View File

@ -180,7 +180,7 @@ func toWslPath(s string) string {
if !ok { if !ok {
return "" return ""
} }
return fmt.Sprintf("mnt/%s%s", drive, p) return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
} }
func parseUNCPath(s string) (drive, p string, ok bool) { func parseUNCPath(s string) (drive, p string, ok bool) {

View File

@ -1,6 +1,7 @@
package command package command
import ( import (
"io/fs"
"net/url" "net/url"
"testing" "testing"
"testing/fstest" "testing/fstest"
@ -9,21 +10,48 @@ import (
) )
func TestWslSocketPath(t *testing.T) { func TestWslSocketPath(t *testing.T) {
u, err := url.Parse("unix:////./c:/my/file/path") testCases := []struct {
assert.NilError(t, err) doc string
fs fs.FS
// Ensure host is empty. url string
assert.Equal(t, u.Host, "") expected string
}{
// Use a filesystem where the WSL path exists. {
fs := fstest.MapFS{ doc: "filesystem where WSL path does not exist",
"mnt/c/my/file/path": {}, fs: fstest.MapFS{
"my/file/path": {},
},
url: "unix:////./c:/my/file/path",
expected: "",
},
{
doc: "filesystem where WSL path exists",
fs: fstest.MapFS{
"mnt/c/my/file/path": {},
},
url: "unix:////./c:/my/file/path",
expected: "/mnt/c/my/file/path",
},
{
doc: "filesystem where WSL path exists uppercase URL",
fs: fstest.MapFS{
"mnt/c/my/file/path": {},
},
url: "unix:////./C:/my/file/path",
expected: "/mnt/c/my/file/path",
},
} }
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
// Use a filesystem where the WSL path doesn't exist. for _, tc := range testCases {
fs = fstest.MapFS{ t.Run(tc.doc, func(t *testing.T) {
"my/file/path": {}, u, err := url.Parse(tc.url)
assert.NilError(t, err)
// Ensure host is empty.
assert.Equal(t, u.Host, "")
result := wslSocketPath(u.Path, tc.fs)
assert.Equal(t, result, tc.expected)
})
} }
assert.Equal(t, wslSocketPath(u.Path, fs), "")
} }