diff --git a/decode_test.go b/decode_test.go index 3999e386..77654e09 100644 --- a/decode_test.go +++ b/decode_test.go @@ -1620,6 +1620,11 @@ var unmarshalStrictTests = []struct { data: "a: 1\nc: 2\n", value: struct{ A, B int }{A: 1}, error: `yaml: unmarshal errors:\n line 2: field c not found in type struct { A int; B int }`, +}, { + known: true, + data: "i: 1\nj: 2\n", + value: customUnmarshaler{I: 2}, + error: `yaml: unmarshal errors:\n line 1: field i not found in type yaml_test.bufT`, }, { unique: true, data: "a: 1\nb: 2\na: 3\n", @@ -1713,6 +1718,22 @@ func (t *textUnmarshaler) UnmarshalText(s []byte) error { return nil } +type customUnmarshaler struct { + I int +} + +func (c *customUnmarshaler) UnmarshalYAML(value *yaml.Node) error { + type bufT struct { + J int + } + var buf bufT + if err := value.Decode(&buf); err != nil { + return err + } + c.I = buf.J + return nil +} + func (s *S) TestFuzzCrashers(c *C) { cases := []string{ // runtime error: index out of range