From 5ef2e442de2be5446002945d8308314592d7c3fd Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Mon, 2 Jan 2023 16:24:40 +0100 Subject: [PATCH] internal/flags: use filepath.Clean instead of path.Clean --- internal/flags/flags.go | 4 ++-- internal/flags/flags_test.go | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 0ae2c6a512ef..9e3719632977 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -23,7 +23,7 @@ import ( "math/big" "os" "os/user" - "path" + "path/filepath" "strings" "github.com/ethereum/go-ethereum/common/math" @@ -319,7 +319,7 @@ func expandPath(p string) string { p = home + p[1:] } } - return path.Clean(os.ExpandEnv(p)) + return filepath.Clean(os.ExpandEnv(p)) } func HomeDir() string { diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go index a0d4af7ca360..f9073cc97e31 100644 --- a/internal/flags/flags_test.go +++ b/internal/flags/flags_test.go @@ -25,11 +25,13 @@ import ( func TestPathExpansion(t *testing.T) { user, _ := user.Current() tests := map[string]string{ - "/home/someuser/tmp": "/home/someuser/tmp", - "~/tmp": user.HomeDir + "/tmp", - "~thisOtherUser/b/": "~thisOtherUser/b", - "$DDDXXX/a/b": "/tmp/a/b", - "/a/b/": "/a/b", + "/home/someuser/tmp": "/home/someuser/tmp", + "~/tmp": user.HomeDir + "/tmp", + "~thisOtherUser/b/": "~thisOtherUser/b", + "$DDDXXX/a/b": "/tmp/a/b", + "/a/b/": "/a/b", + "C:\\Documents\\Newsletters\\": "C:\\Documents\\Newsletters\\", + "C:\\": "C:\\", } os.Setenv("DDDXXX", "/tmp") for test, expected := range tests {