Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: make parsing configurations without usable values invalid (backport) #4358

Merged
merged 1 commit into from Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion conf/parse.go
Expand Up @@ -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
}

Expand Down
27 changes: 27 additions & 0 deletions conf/parse_test.go
Expand Up @@ -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")
}
}
}