diff --git a/conf/parse.go b/conf/parse.go index 612b1643..4d2a20ad 100644 --- a/conf/parse.go +++ b/conf/parse.go @@ -146,7 +146,9 @@ func parse(data, fp string, pedantic bool) (p *parser, err error) { return nil, err } } - + if len(p.mapping) == 0 { + return nil, fmt.Errorf("config has no values or is empty") + } return p, nil } diff --git a/conf/parse_test.go b/conf/parse_test.go index 4c8c07fb..3fc7c927 100644 --- a/conf/parse_test.go +++ b/conf/parse_test.go @@ -403,3 +403,30 @@ func TestParserNoInfiniteLoop(t *testing.T) { } } } + +func TestParseWithNoValues(t *testing.T) { + for _, test := range []string{ + ``, + `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`, + ` aaaaaaaaaaaaaaaaaaaaaaaaaaa`, + ` aaaaaaaaaaaaaaaaaaaaaaaaaaa `, + ` + # just comments with no values + # is also invalid. + `, + ` + # with comments and no spaces to create key values + # is also an invalid config. + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + `, + ` + a,a,a,a,a,a,a,a,a,a,a + `, + } { + if _, err := parse(test, "", true); err == nil { + t.Fatal("expected an error") + } else if !strings.Contains(err.Error(), "config has no values or is empty") { + t.Fatal("expected invalid conf error") + } + } +}