Permalink
Browse files

Fix unmarshaler handling of empty strings.

1 parent 31c2992 commit a5b47d31c556af34a302ce5d659e6fea44d90de0 @niemeyer niemeyer committed Sep 28, 2016
Showing with 2 additions and 1 deletion.
  1. +1 −1 decode.go
  2. +1 −0 decode_test.go
View
@@ -251,7 +251,7 @@ func (d *decoder) callUnmarshaler(n *node, u Unmarshaler) (good bool) {
//
// If n holds a null value, prepare returns before doing anything.
func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) {
- if n.tag == yaml_NULL_TAG || n.kind == scalarNode && n.tag == "" && (n.value == "null" || n.value == "") {
+ if n.tag == yaml_NULL_TAG || n.kind == scalarNode && n.tag == "" && (n.value == "null" || n.value == "" && n.implicit) {
return out, false, false
}
again := true
View
@@ -660,6 +660,7 @@ var unmarshalerTests = []struct {
{`_: BAR!`, "!!str", "BAR!"},
{`_: "BAR!"`, "!!str", "BAR!"},
{"_: !!foo 'BAR!'", "!!foo", "BAR!"},
+ {`_: ""`, "!!str", ""},
}
var unmarshalerResult = map[int]error{}

0 comments on commit a5b47d3

Please sign in to comment.