From 55767e32562caa50a41e5afc186ed3d23c58b9d1 Mon Sep 17 00:00:00 2001 From: sawka Date: Mon, 14 Nov 2022 13:56:50 -0800 Subject: [PATCH] remove shellescape dependency --- pkg/utilfn/utilfn.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/utilfn/utilfn.go b/pkg/utilfn/utilfn.go index b8e4a7c79..35db1c4df 100644 --- a/pkg/utilfn/utilfn.go +++ b/pkg/utilfn/utilfn.go @@ -1,9 +1,8 @@ package utilfn import ( + "regexp" "strings" - - "github.com/alessio/shellescape" ) func GetStrArr(v interface{}, field string) []string { @@ -50,12 +49,17 @@ func GetBool(v interface{}, field string) bool { return bval } +var needsQuoteRe = regexp.MustCompile(`[^\w@%:,./=+-]`) + // minimum maxlen=6 func ShellQuote(val string, forceQuote bool, maxLen int) string { if maxLen < 6 { maxLen = 6 } - rtn := shellescape.Quote(val) + rtn := val + if needsQuoteRe.MatchString(val) { + rtn = "'" + strings.ReplaceAll(val, "'", `'"'"'`) + "'" + } if strings.HasPrefix(rtn, "\"") || strings.HasPrefix(rtn, "'") { if len(rtn) > maxLen { return rtn[0:maxLen-4] + "..." + rtn[0:1]