From 25cc74c6817fec132fa02678bab1aa4b2d10c1e3 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 6 Nov 2024 18:31:42 +0000 Subject: [PATCH] Fix support for the absolute path / --- storage/uri.go | 8 ++++++-- storage/uri_test.go | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/storage/uri.go b/storage/uri.go index af4ea53b9c..2e900e0719 100644 --- a/storage/uri.go +++ b/storage/uri.go @@ -11,8 +11,12 @@ import ( // Relative paths will be converted to absolute using filepath.Abs if required. func NewFileURI(path string) fyne.URI { assumeAbs := false - if len(path) >= 2 { - assumeAbs = path[1] == ':' || path[0] == '/' + if len(path) >= 1 { + if path[0] == '/' { + assumeAbs = true + } else if len(path) >= 2 { + assumeAbs = path[1] == ':' + } } if !assumeAbs { diff --git a/storage/uri_test.go b/storage/uri_test.go index 9fe2d9bd6f..40741c8f64 100644 --- a/storage/uri_test.go +++ b/storage/uri_test.go @@ -247,6 +247,8 @@ func TestFileAbs(t *testing.T) { assert.Equal(t, abs.Path(), rel.Path()) assert.Equal(t, abs.String(), rel.String()) + + assert.Equal(t, "file:///", storage.NewFileURI("/").String()) } func TestWriteAndDelete(t *testing.T) {