From e364698f17de10cf72216aaa9c2f67cdeeccd7f8 Mon Sep 17 00:00:00 2001 From: Inteon <42113979+inteon@users.noreply.github.com> Date: Sat, 23 Oct 2021 11:31:35 +0200 Subject: [PATCH] continue decoding if strict error occures Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com> --- decode.go | 15 --------------- decode_test.go | 2 ++ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/decode.go b/decode.go index a12e2f0c..5f05e885 100644 --- a/decode.go +++ b/decode.go @@ -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 { @@ -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: @@ -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 { @@ -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) diff --git a/decode_test.go b/decode_test.go index e02eedde..016d6efb 100644 --- a/decode_test.go +++ b/decode_test.go @@ -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) } } @@ -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) } } }