From 81205292aba40f8868069e2f18d90043d3e724a6 Mon Sep 17 00:00:00 2001 From: Gustavo Niemeyer Date: Fri, 11 Apr 2014 15:11:20 -0300 Subject: [PATCH] Call setter on explicitly quoted strings. Fixes #7. --- decode.go | 7 ++++--- decode_test.go | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/decode.go b/decode.go index fd1ff96..75a2c42 100644 --- a/decode.go +++ b/decode.go @@ -283,12 +283,13 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) { var tag string var resolved interface{} if n.tag == "" && !n.implicit { + tag = "!!str" resolved = n.value } else { tag, resolved = resolve(n.tag, n.value) - if set := d.setter(tag, &out, &good); set != nil { - defer set() - } + } + if set := d.setter(tag, &out, &good); set != nil { + defer set() } switch out.Kind() { case reflect.String: diff --git a/decode_test.go b/decode_test.go index 224e369..55db804 100644 --- a/decode_test.go +++ b/decode_test.go @@ -435,6 +435,8 @@ var setterTests = []struct { {"_: [1,A]", "!!seq", []interface{}{1, "A"}}, {"_: 10", "!!int", 10}, {"_: null", "!!null", nil}, + {`_: BAR!`, "!!str", "BAR!"}, + {`_: "BAR!"`, "!!str", "BAR!"}, {"_: !!foo 'BAR!'", "!!foo", "BAR!"}, } @@ -491,7 +493,7 @@ func (s *S) TestUnmarshalWithFalseSetterIgnoresValue(c *C) { }() m := map[string]*typeWithSetter{} - data := "{abc: 1, def: 2, ghi: 3, jkl: 4}" + data := `{abc: 1, def: 2, ghi: 3, jkl: 4}` err := yaml.Unmarshal([]byte(data), m) c.Assert(err, IsNil) c.Assert(m["abc"], NotNil)