Skip to content

Commit 13210f3

Browse files
committed
nit: move metacharRegex to package-level
1 parent c27dd75 commit 13210f3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/oci/runtime_syscall_exec.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import (
3131
// These metacharacters include: | & ; ( ) < > \t \n $ \ `
3232
const shellMetachars = "|&;()<> \t\n$\\`"
3333

34+
// metacharRegex matches any shell metacharcter.
35+
var metacharRegex = regexp.MustCompile(`([` + regexp.QuoteMeta(shellMetachars) + `])`)
36+
3437
type syscallExec struct{}
3538

3639
var _ Runtime = (*syscallExec)(nil)
@@ -54,7 +57,7 @@ func (r syscallExec) String() string {
5457
// Escape1 escapes shell metacharacters in a single command-line argument.
5558
func 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

0 commit comments

Comments
 (0)