File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ import (
3131// These metacharacters include: | & ; ( ) < > \t \n $ \ `
3232const shellMetachars = "|&;()<> \t \n $\\ `"
3333
34+ // metacharRegex matches any shell metacharcter.
35+ var metacharRegex = regexp .MustCompile (`([` + regexp .QuoteMeta (shellMetachars ) + `])` )
36+
3437type syscallExec struct {}
3538
3639var _ Runtime = (* syscallExec )(nil )
@@ -54,7 +57,7 @@ func (r syscallExec) String() string {
5457// Escape1 escapes shell metacharacters in a single command-line argument.
5558func Escape1 (arg string ) string {
5659 if strings .ContainsAny (arg , shellMetachars ) {
57- e := regexp . MustCompile ( `([|&;()<> \t\n$\\` + "`" + `])` ) .ReplaceAllString (arg , `\$1` )
60+ e := metacharRegex .ReplaceAllString (arg , `\$1` )
5861 return fmt .Sprintf (`"%s"` , e )
5962 }
6063 return arg
You can’t perform that action at this time.
0 commit comments