Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions empty_file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package properties

import "testing"

func TestLoadFileEmptyPath(t *testing.T) {
if _, err := LoadFile(" ", UTF8); err == nil {
t.Fatal("expected error")
}
if _, err := LoadFile("", UTF8); err == nil {
t.Fatal("expected error")
}
}
4 changes: 4 additions & 0 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func LoadMap(m map[string]string) *Properties {

// LoadFile reads a file into a Properties struct.
func LoadFile(filename string, enc Encoding) (*Properties, error) {
filename = strings.TrimSpace(filename)
if filename == "" {
return nil, fmt.Errorf("properties: empty filename")
}
l := &Loader{Encoding: enc}
return l.LoadAll([]string{filename})
}
Expand Down
Loading