mirror of
https://github.com/aykhans/sarin.git
synced 2026-10-17 06:53:52 +00:00
fix(config): reject unknown fields in a YAML config file
This commit is contained in:
1 file changed
+5
-2
@@ -1,6 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -235,8 +236,10 @@ func (parser ConfigFileParser) ParseYAML(data []byte) (*Config, error) {
|
|||||||
parsedData = &configYAML{}
|
parsedData = &configYAML{}
|
||||||
)
|
)
|
||||||
|
|
||||||
err := yaml.Unmarshal(data, &parsedData)
|
decoder := yaml.NewDecoder(bytes.NewReader(data))
|
||||||
if err != nil {
|
decoder.KnownFields(true)
|
||||||
|
// The decoder returns a bare io.EOF for an empty file, errors.Is would also match a wrapped one.
|
||||||
|
if err := decoder.Decode(parsedData); err != nil && err != io.EOF { //nolint:errorlint
|
||||||
return nil, types.NewUnmarshalError(err)
|
return nil, types.NewUnmarshalError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user