Skip to content

Commit

Permalink
Fix panic on invalid file URI fyne-io#3275
Browse files Browse the repository at this point in the history
  • Loading branch information
ChandanChainani committed Oct 5, 2022
1 parent 94713bb commit 6cfc025
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
15 changes: 9 additions & 6 deletions storage/repository/parse.go
Expand Up @@ -59,13 +59,16 @@ func ParseURI(s string) (fyne.URI, error) {
// we should punt this to whoever generated the URI in the
// first place?

path := s[5:] // everything after file:
if len(path) > 2 && path[:2] == "//" {
path = path[2:]
if len(s) > 5 {
path := s[5:] // everything after file:
if len(path) > 2 && path[:2] == "//" {
path = path[2:]
}

// Windows files can break authority checks, so just return the parsed file URI
return NewFileURI(path), nil
}

// Windows files can break authority checks, so just return the parsed file URI
return NewFileURI(path), nil
return nil, errors.New("not a valid URI")
}

repo, err := ForScheme(scheme)
Expand Down
20 changes: 20 additions & 0 deletions theme/json_test.go
Expand Up @@ -28,6 +28,26 @@ func TestFromJSON(t *testing.T) {
assert.Equal(t, float32(5), th.Size(SizeNameInlineIcon))
assert.Equal(t, "NotoMono-Regular.ttf", th.Font(fyne.TextStyle{Monospace: true}).Name())
assert.Equal(t, "cancel_Paths.svg", th.Icon(IconNameCancel).Name())

th, err = FromJSON(`{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"F
`)
assert.Nil(t, err)
th.Font(fyne.TextStyle{Monospace: true}).Name()
}

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

0 comments on commit 6cfc025

Please sign in to comment.