Skip to content

Commit

Permalink
Fix panic at decoding of inlining pointer type with DisallowUnknownFi…
Browse files Browse the repository at this point in the history
…eld option
  • Loading branch information
goccy committed Jun 8, 2020
1 parent 296b97b commit 3eacf18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,17 @@ func errDuplicateKey(msg string, tk *token.Token) *duplicateKeyError {
}

func (d *Decoder) deleteStructKeys(structValue reflect.Value, unknownFields map[string]ast.Node) error {
strType := structValue.Type()
structFieldMap, err := structFieldMap(strType)
structType := structValue.Type()
if structType.Kind() == reflect.Ptr {
structType = structType.Elem()
}
structFieldMap, err := structFieldMap(structType)
if err != nil {
return errors.Wrapf(err, "failed to create struct field map")
}

for j := 0; j < strType.NumField(); j++ {
field := structValue.Type().Field(j)
for j := 0; j < structType.NumField(); j++ {
field := structType.Field(j)
if isIgnoredStructField(field) {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,8 @@ c:
})
t.Run("inline", func(t *testing.T) {
var v struct {
Child `yaml:",inline"`
A string `yaml:"a"`
*Child `yaml:",inline"`
A string `yaml:"a"`
}
yml := `---
a: a
Expand Down

0 comments on commit 3eacf18

Please sign in to comment.