diff --git a/mmv.go b/mmv.go index 4b69fc1..be8faf9 100644 --- a/mmv.go +++ b/mmv.go @@ -47,6 +47,11 @@ func buildRenames(files map[string]string) ([]rename, error) { if src == "" || dst == "" { return nil, &emptyPathError{} } + if d := filepath.Clean(src); d != src { + delete(files, src) + src = d + files[src] = dst + } if d := filepath.Clean(dst); d != dst { dst = d files[src] = dst diff --git a/mmv_test.go b/mmv_test.go index e5352a6..aa0df40 100644 --- a/mmv_test.go +++ b/mmv_test.go @@ -170,6 +170,22 @@ func TestRename(t *testing.T) { }, err: &sameDestinationError{"baz"}, }, + { + name: "clean source path", + files: map[string]string{ + "foo": "bar", + "bar/": "foo/", + }, + cnt: 3, + contents: map[string]string{ + "foo": "0", + "bar": "1", + }, + expected: map[string]string{ + "bar": "0", + "foo": "1", + }, + }, { name: "cleaned path same destination error", files: map[string]string{