File tree Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import (
29
29
// properly handled.
30
30
//
31
31
// These metacharacters include: | & ; ( ) < > \t \n $ \ `
32
- const shellMetachars = "|&;()<> \t \n $\\ `"
32
+ const shellMetachars = "|&;()<> \t \n $\\ `' \" "
33
33
34
34
// metacharRegex matches any shell metacharcter.
35
35
var metacharRegex = regexp .MustCompile (`([` + regexp .QuoteMeta (shellMetachars ) + `])` )
@@ -54,11 +54,10 @@ func (r syscallExec) String() string {
54
54
return "exec"
55
55
}
56
56
57
- // Escape1 escapes shell metacharacters in a single command-line argument.
58
- func Escape1 (arg string ) string {
57
+ // escapeArg escapes shell metacharacters in a single command-line argument.
58
+ func escapeArg (arg string ) string {
59
59
if strings .ContainsAny (arg , shellMetachars ) {
60
- e := metacharRegex .ReplaceAllString (arg , `\$1` )
61
- return fmt .Sprintf (`"%s"` , e )
60
+ return metacharRegex .ReplaceAllString (arg , `\$1` )
62
61
}
63
62
return arg
64
63
}
@@ -68,7 +67,7 @@ func Escape1(arg string) string {
68
67
func Escape (args []string ) []string {
69
68
escaped := make ([]string , len (args ))
70
69
for i := range args {
71
- escaped [i ] = Escape1 (args [i ])
70
+ escaped [i ] = escapeArg (args [i ])
72
71
}
73
72
return escaped
74
73
}
Original file line number Diff line number Diff line change 1
1
/*
2
- # Copyright (c) 2021 , NVIDIA CORPORATION. All rights reserved.
2
+ # Copyright (c) 2025 , NVIDIA CORPORATION. All rights reserved.
3
3
#
4
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
5
# you may not use this file except in compliance with the License.
You can’t perform that action at this time.
0 commit comments