diff --git a/empty_file_test.go b/empty_file_test.go new file mode 100644 index 0000000..9aeb739 --- /dev/null +++ b/empty_file_test.go @@ -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") + } +} diff --git a/load.go b/load.go index 3d5573f..57337aa 100644 --- a/load.go +++ b/load.go @@ -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}) }