check destination error on cleaned path

This commit is contained in:
itchyny 2020-01-08 00:20:42 +09:00
parent 0e578e6b83
commit 72dc9b0e83
2 changed files with 16 additions and 0 deletions

4
mmv.go
View file

@ -47,6 +47,10 @@ func buildRenames(files map[string]string) ([]rename, error) {
if src == "" || dst == "" {
return nil, &emptyPathError{}
}
if d := filepath.Clean(dst); d != dst {
dst = d
files[src] = dst
}
if _, ok := revs[dst]; ok {
return nil, &sameDestinationError{dst}
}

View file

@ -170,6 +170,18 @@ func TestMove(t *testing.T) {
},
err: &sameDestinationError{"baz"},
},
{
name: "cleaned path same destination error",
files: map[string]string{
"foo": "baz",
"bar": "foo/../baz",
},
contents: map[string]string{
"foo": "0",
"bar": "1",
},
err: &sameDestinationError{"baz"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {