From 72dc9b0e830824b439a32555d0cba5b8bdb4093f Mon Sep 17 00:00:00 2001 From: itchyny Date: Wed, 8 Jan 2020 00:20:42 +0900 Subject: [PATCH] check destination error on cleaned path --- mmv.go | 4 ++++ mmv_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/mmv.go b/mmv.go index eaa2b31..ca101b4 100644 --- a/mmv.go +++ b/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} } diff --git a/mmv_test.go b/mmv_test.go index 05e7724..a799ce6 100644 --- a/mmv_test.go +++ b/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) {