Skip to content

Commit eae1191

Browse files
committed
cmd/utils: fix path expansion on windows
1 parent 78b101e commit eae1191

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

‎cmd/utils/customflags.go‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"os/user"
24-
"path/filepath"
24+
"path"
2525
"strings"
2626

2727
"github.com/codegangsta/cli"
@@ -138,11 +138,8 @@ func (self *DirectoryFlag) Set(value string) {
138138
func expandPath(p string) string {
139139
if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") {
140140
if user, err := user.Current(); err == nil {
141-
if err == nil {
142-
p = strings.Replace(p, "~", user.HomeDir, 1)
143-
}
141+
p = user.HomeDir + p[1:]
144142
}
145143
}
146-
147-
return filepath.Clean(os.ExpandEnv(p))
144+
return path.Clean(os.ExpandEnv(p))
148145
}

‎cmd/utils/customflags_test.go‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ import (
2323
)
2424

2525
func TestPathExpansion(t *testing.T) {
26-
2726
user, _ := user.Current()
28-
2927
tests := map[string]string{
3028
"/home/someuser/tmp": "/home/someuser/tmp",
3129
"~/tmp": user.HomeDir + "/tmp",
30+
"~thisOtherUser/b/": "~thisOtherUser/b",
3231
"$DDDXXX/a/b": "/tmp/a/b",
3332
"/a/b/": "/a/b",
3433
}
35-
3634
os.Setenv("DDDXXX", "/tmp")
37-
3835
for test, expected := range tests {
3936
got := expandPath(test)
4037
if got != expected {

0 commit comments

Comments
 (0)