diff --git a/pkg/fs/base.go b/pkg/fs/base.go index 749749c55..6a7fdaa8a 100644 --- a/pkg/fs/base.go +++ b/pkg/fs/base.go @@ -29,7 +29,7 @@ func Base(fileName string, stripSequence bool) string { } // other common sequential naming schemes - if end := strings.Index(basename, " ("); end != -1 { + if end := strings.Index(basename, "("); end != -1 { // copies created by Chrome & Windows, example: IMG_1234 (2) basename = basename[:end] } else if end := strings.Index(basename, " copy"); end != -1 { @@ -37,6 +37,8 @@ func Base(fileName string, stripSequence bool) string { basename = basename[:end] } + basename = strings.TrimSpace(basename) + return basename } diff --git a/pkg/fs/base_test.go b/pkg/fs/base_test.go index 0ce086915..93e2ca6e0 100644 --- a/pkg/fs/base_test.go +++ b/pkg/fs/base_test.go @@ -67,6 +67,26 @@ func TestBase(t *testing.T) { result := Base("/testdata/Test (3).jpg", false) assert.Equal(t, "Test (3)", result) }) + t.Run("20180506_091537_DSC02122.JPG", func(t *testing.T) { + result := Base("20180506_091537_DSC02122.JPG", true) + assert.Equal(t, "20180506_091537_DSC02122", result) + }) + t.Run("20180506_091537_DSC02122 (+3.3).JPG", func(t *testing.T) { + result := Base("20180506_091537_DSC02122 (+3.3).JPG", true) + assert.Equal(t, "20180506_091537_DSC02122", result) + }) + t.Run("20180506_091537_DSC02122 (-2.7).JPG", func(t *testing.T) { + result := Base("20180506_091537_DSC02122 (-2.7).JPG", true) + assert.Equal(t, "20180506_091537_DSC02122", result) + }) + t.Run("20180506_091537_DSC02122(+3.3).JPG", func(t *testing.T) { + result := Base("20180506_091537_DSC02122(+3.3).JPG", true) + assert.Equal(t, "20180506_091537_DSC02122", result) + }) + t.Run("20180506_091537_DSC02122(-2.7).JPG", func(t *testing.T) { + result := Base("20180506_091537_DSC02122(-2.7).JPG", true) + assert.Equal(t, "20180506_091537_DSC02122", result) + }) } func TestRelativeBase(t *testing.T) {