Skip to content

Commit

Permalink
continue decoding if strict error occures
Browse files Browse the repository at this point in the history
Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Oct 23, 2021
1 parent a69ce44 commit e364698
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
15 changes: 0 additions & 15 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ func (d *decoder) sequence(n *Node, out reflect.Value) (good bool) {
func (d *decoder) mapping(n *Node, out reflect.Value) (good bool) {
l := len(n.Content)
if d.uniqueKeys {
nerrs := len(d.strictTerrors)
for i := 0; i < l; i += 2 {
ni := n.Content[i]
for j := i + 2; j < l; j += 2 {
Expand All @@ -775,9 +774,6 @@ func (d *decoder) mapping(n *Node, out reflect.Value) (good bool) {
}
}
}
if len(d.strictTerrors) > nerrs {
return false
}
}
switch out.Kind() {
case reflect.Struct:
Expand Down Expand Up @@ -873,10 +869,6 @@ func (d *decoder) mappingStruct(n *Node, out reflect.Value) (good bool) {
d.prepare(n, field)
}

var doneFields []bool
if d.uniqueKeys {
doneFields = make([]bool, len(sinfo.FieldsList))
}
name := settableValueOf("")
l := len(n.Content)
for i := 0; i < l; i += 2 {
Expand All @@ -889,13 +881,6 @@ func (d *decoder) mappingStruct(n *Node, out reflect.Value) (good bool) {
continue
}
if info, ok := sinfo.FieldsMap[name.String()]; ok {
if d.uniqueKeys {
if doneFields[info.Id] {
d.strictTerrors = append(d.strictTerrors, fmt.Sprintf("line %d: field %s already set in type %s", ni.Line, name.String(), out.Type()))
continue
}
doneFields[info.Id] = true
}
var field reflect.Value
if info.Inline == nil {
field = out.Field(info.Num)
Expand Down
2 changes: 2 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,7 @@ func (s *S) TestUnmarshalKnownFields(c *C) {
dec.KnownFields(item.known)
err := dec.Decode(value.Interface())
c.Assert(err, ErrorMatches, item.error)
c.Assert(value.Elem().Interface(), DeepEquals, item.value)
}
}

Expand Down Expand Up @@ -1712,6 +1713,7 @@ func (s *S) TestDisableUniqueKeys(c *C) {
c.Assert(value.Elem().Interface(), DeepEquals, item.value)
} else {
c.Assert(err, ErrorMatches, item.error)
c.Assert(value.Elem().Interface(), DeepEquals, item.value)
}
}
}
Expand Down

0 comments on commit e364698

Please sign in to comment.