Skip to content

Commit

Permalink
Merge pull request #4282 from andydotxyz/fix/4271
Browse files Browse the repository at this point in the history
Check if uri is empty rather than assuming /
  • Loading branch information
andydotxyz authored Sep 25, 2023
2 parents f6cb0fe + 3e648da commit 72ffd6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/repository/memory.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package repository

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/storage/repository"

"fmt"
"io"
"strings"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/storage/repository"
)

// declare conformance to interfaces
Expand Down Expand Up @@ -297,7 +297,7 @@ func (m *InMemoryRepository) List(u fyne.URI) ([]fyne.URI, error) {
// does not have one.
pSplit := strings.Split(p, "/")
ncomp := len(pSplit)
if p[len(p)-1] == '/' {
if len(p) > 0 && p[len(p)-1] == '/' {
ncomp--
}

Expand Down
10 changes: 10 additions & 0 deletions internal/repository/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func TestInMemoryRepositoryParsing(t *testing.T) {
baz, _ := storage.ParseURI("mem:///baz")
assert.Nil(t, err)
assert.NotNil(t, baz)

empty, _ := storage.ParseURI("mem:")
assert.Nil(t, err)
assert.NotNil(t, empty)
}

func TestInMemoryRepositoryExists(t *testing.T) {
Expand Down Expand Up @@ -328,6 +332,7 @@ func TestInMemoryRepositoryListing(t *testing.T) {
// set up our repository - it's OK if we already registered it
m := NewInMemoryRepository("mem")
repository.Register("mem", m)
m.Data[""] = []byte{1, 2, 3}
m.Data["/foo"] = []byte{1, 2, 3}
m.Data["/foo/bar"] = []byte{1, 2, 3}
m.Data["/foo/baz/"] = []byte{1, 2, 3}
Expand All @@ -346,6 +351,11 @@ func TestInMemoryRepositoryListing(t *testing.T) {
stringListing = append(stringListing, u.String())
}
assert.ElementsMatch(t, []string{"mem:///foo/bar", "mem:///foo/baz/"}, stringListing)

empty, _ := storage.ParseURI("mem:") // invalid path
canList, err = storage.CanList(empty)
assert.NotNil(t, err)
assert.False(t, canList)
}

func TestInMemoryRepositoryCreateListable(t *testing.T) {
Expand Down

0 comments on commit 72ffd6a

Please sign in to comment.