update:optimize slice find and Unquote func (#5108)

This commit is contained in:
me-cs
2025-09-07 08:41:45 +08:00
committed by GitHub
parent 3854d6dd00
commit 06502d1115
2 changed files with 21 additions and 30 deletions

View File

@@ -16,8 +16,10 @@ func getBoolFromKVOrDefault(properties map[string]string, key string, def bool)
if len(val) == 0 {
return def
}
str := util.Unquote(val[0])
if len(str) == 0 {
//I think this function and those below should handle error, but they didn't.
//Since a default value (def) is provided, any parsing errors will result in the default being returned.
str, err := strconv.Unquote(val[0])
if err != nil || len(str) == 0 {
return def
}
res, _ := strconv.ParseBool(str)
@@ -33,8 +35,8 @@ func getStringFromKVOrDefault(properties map[string]string, key string, def stri
if len(val) == 0 {
return def
}
str := util.Unquote(val[0])
if len(str) == 0 {
str, err := strconv.Unquote(val[0])
if err != nil || len(str) == 0 {
return def
}
return str
@@ -50,8 +52,8 @@ func getListFromInfoOrDefault(properties map[string]string, key string, def []st
return def
}
str := util.Unquote(val[0])
if len(str) == 0 {
str, err := strconv.Unquote(val[0])
if err != nil || len(str) == 0 {
return def
}
resp := util.FieldsAndTrimSpace(str, commaRune)
@@ -66,8 +68,8 @@ func getFirstUsableString(def ...string) string {
return ""
}
for _, val := range def {
str := util.Unquote(val)
if len(str) != 0 {
str, err := strconv.Unquote(val)
if err == nil && len(str) != 0 {
return str
}
}