Skip to content

Commit

Permalink
Make file filter case-insensitive (#1185)
Browse files Browse the repository at this point in the history
Curently, a file filter set as ".jpg" would not pick up and files that was saved using ".JPG". This updates the filter to use strings.EqualFold() for case-insensitive lookup.
  • Loading branch information
Jacalz committed Jul 20, 2020
1 parent f41b9b5 commit 74546f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion storage/filter.go
Expand Up @@ -27,7 +27,7 @@ type MimeTypeFileFilter struct {
func (e *ExtensionFileFilter) Matches(uri fyne.URI) bool {
extension := uri.Extension()
for _, ext := range e.Extensions {
if extension == ext {
if strings.EqualFold(extension, ext) {
return true
}
}
Expand Down
25 changes: 25 additions & 0 deletions storage/filter_test.go
@@ -0,0 +1,25 @@
package storage_test

import (
"testing"

"fyne.io/fyne/storage"

_ "fyne.io/fyne/test"

"github.com/stretchr/testify/assert"
)

func TestFIleFilter(t *testing.T) {
filter := storage.NewExtensionFileFilter([]string{".jpg", ".png"})

assert.NotNil(t, filter)
assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.JPG")))
assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.jpg")))

assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.PNG")))
assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.png")))

assert.Equal(t, false, filter.Matches(storage.NewURI("content:///otherapp/something/pic.TIFF")))
assert.Equal(t, false, filter.Matches(storage.NewURI("content:///otherapp/something/pic.tiff")))
}

0 comments on commit 74546f8

Please sign in to comment.