Skip to content

Commit

Permalink
Merge pull request #123 from goccy/feature/fix-issue-121
Browse files Browse the repository at this point in the history
Fix panic at decoding of inlining pointer type with DisallowUnknownField option
  • Loading branch information
goccy authored Jun 8, 2020
2 parents 296b97b + 3eacf18 commit 85a4ca1
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 85a4ca1

Please sign in to comment.