mirror of
https://github.com/itchyny/mmv.git
synced 2025-12-26 14:14:57 +08:00
check destination error on cleaned path
This commit is contained in:
parent
0e578e6b83
commit
72dc9b0e83
2 changed files with 16 additions and 0 deletions
4
mmv.go
4
mmv.go
|
|
@ -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}
|
||||
}
|
||||
|
|
|
|||
12
mmv_test.go
12
mmv_test.go
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue