fix: process null value in yaml (#37418)

issue: #34298 
fix key: null defined in the yaml file. 
viper will parse it as "", and yaml v3 will parse it as "null".

Signed-off-by: xianliang.li <xianliang.li@zilliz.com>
This commit is contained in:
foxspy 2024-11-04 21:46:23 +08:00 committed by GitHub
parent 9fe90bf357
commit 1b98bb423a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -96,9 +96,15 @@ func flattenNode(node *yaml.Node, parentKey string, result map[string]string) {
switch valueNode.Kind {
case yaml.ScalarNode:
// Scalar value, store it as a string
result[lowerKey(fullKey)] = valueNode.Value
result[formatKey(fullKey)] = valueNode.Value
// handle null value
if valueNode.Tag == "!!null" {
result[lowerKey(fullKey)] = ""
result[formatKey(fullKey)] = ""
} else {
// Scalar value, store it as a string
result[lowerKey(fullKey)] = valueNode.Value
result[formatKey(fullKey)] = valueNode.Value
}
case yaml.MappingNode:
// Nested map, process recursively
flattenNode(valueNode, fullKey, result)