Loading an empty file yields a nil (#906)

## Changes

Empty YAML files are valid and should return a nil-equivalent when
loaded.

## Tests

Tests pass.
This commit is contained in:
Pieter Noordhuis 2023-10-24 13:24:43 +02:00 committed by GitHub
parent 5018059444
commit 3411b8aa37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

View File

@ -12,6 +12,9 @@ func LoadYAML(path string, r io.Reader) (config.Value, error) {
dec := yaml.NewDecoder(r)
err := dec.Decode(&node)
if err != nil {
if err == io.EOF {
return config.NilValue, nil
}
return config.NilValue, err
}

View File

@ -28,3 +28,8 @@ func loadYAML(t *testing.T, path string) config.Value {
assert.EqualValues(t, ref, self.AsAny())
return self
}
func TestYAMLEmpty(t *testing.T) {
self := loadYAML(t, "testdata/empty.yml")
assert.Equal(t, config.NilValue, self)
}