变量修饰符增加quote

This commit is contained in:
刘祥超
2024-05-01 19:44:11 +08:00
parent c3c3261579
commit 799d186f85
2 changed files with 27 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
stringutil "github.com/iwind/TeaGo/utils/string" stringutil "github.com/iwind/TeaGo/utils/string"
"net/url" "net/url"
"regexp" "regexp"
"strconv"
"strings" "strings"
"sync" "sync"
) )
@@ -183,6 +184,9 @@ func doStringModifiers(value string, modifiers []string) string {
value = strings.ToLower(value) value = strings.ToLower(value)
case "toUpperCase": case "toUpperCase":
value = strings.ToUpper(value) value = strings.ToUpper(value)
case "quote":
value = strconv.Quote(value)
} }
} }
return value return value

View File

@@ -115,6 +115,29 @@ func TestParseVariables_Modifier(t *testing.T) {
} }
return "${" + varName + "}" return "${" + varName + "}"
})) }))
// quote
t.Log("quote(abc)", "=>", configutils.ParseVariables("${var|quote}", func(varName string) (value string) {
switch varName {
case "var":
return "abc"
}
return "${" + varName + "}"
}))
t.Log("quote(\"ABC\"123)", "=>", configutils.ParseVariables("${var|quote}", func(varName string) (value string) {
switch varName {
case "var":
return "\"ABC\"123"
}
return "${" + varName + "}"
}))
t.Log("quote('ABC'123)", "=>", configutils.ParseVariables("${var|quote}", func(varName string) (value string) {
switch varName {
case "var":
return "'ABC'123"
}
return "${" + varName + "}"
}))
} }
func TestParseHolders(t *testing.T) { func TestParseHolders(t *testing.T) {