Merge pull request #2570 from mortent/FixEmptyStringHandling

Treat empty strings as string type instead of null type
This commit is contained in:
Kubernetes Prow Robot
2020-06-05 15:23:46 -07:00
committed by GitHub
2 changed files with 5 additions and 1 deletions

View File

@@ -70,6 +70,9 @@ func IsYaml1_1NonString(node *Node) bool {
}
func IsValueNonString(value string) bool {
if value == "" {
return false
}
if strings.Contains(value, "\n") {
// multi-line strings will fail to unmarshal
return false

View File

@@ -23,6 +23,7 @@ func TestIsYaml1_1NonString(t *testing.T) {
{val: "2", expected: true},
{val: "true", expected: true},
{val: "1.0\nhello", expected: false}, // multiline strings should always be false
{val: "", expected: false}, // empty string should be considered a string
}
for k := range valueToTagMap {
@@ -111,7 +112,7 @@ var valueToTagMap = func() map[string]string {
val := map[string]string{}
// https://yaml.org/type/null.html
values := []string{"", "~", "null", "Null", "NULL"}
values := []string{"~", "null", "Null", "NULL"}
for i := range values {
val[values[i]] = "!!null"
}