mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 04:55:08 +00:00
Merge pull request #2570 from mortent/FixEmptyStringHandling
Treat empty strings as string type instead of null type
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user