变量修饰符增加quote

This commit is contained in:
GoEdgeLab
2024-05-01 19:44:11 +08:00
parent 26efc2ba34
commit 5dfe3044d1
2 changed files with 27 additions and 0 deletions

View File

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

View File

@@ -115,6 +115,29 @@ func TestParseVariables_Modifier(t *testing.T) {
}
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) {