go-yaml/yaml — pull request #57 by ghodss (2014-11-25 02:36:24+00:00)
Title: Fix: Call UnmarshalYAML on literal empty string values

If you have the YAML `a: ""\n`, and the `a` field corresponds to a struct, UnmarshalYAML is not called on the struct. Instead, decoder.prepare(...) short-circuits and fails to parse with an error: `cannot unmarshal !!str `` into `.

I've added an example at the end of decode_test.go, but a practical example exists in the [Kubernetes project struct util.IntOrString](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/util/util.go#L63). With IntOrString, a YAML value turns into an IntOrString object which is created and filled in differently whether the value is an int or string in the YAML. So, `a: ""\n` and `a: 0\n` should both have UnmarshalYAML called on an IntOrString object, but `a: null\n` and `a: \n` both should have a zeroed out IntOrString object automatically created (or a nil pointer if the type is *IntOrString).

YAML v1 has the correct behavior since `a: ""\n` results in a call to UnmarshalYAML, and `a: null\n` and `a: \n` result in zeroed objects. This change breaks no existing tests and fixes the v2 regression. This change is also necessary for Kubernetes to upgrade from YAML v1 to v2 - see GoogleCloudPlatform/kubernetes#2490.