File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,15 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
9090 return r .Run (ctx , p )
9191}
9292
93+ func escape (s string ) string {
94+ s = filepath .ToSlash (s )
95+ s = strings .ReplaceAll (s , " " , `\ ` )
96+ s = strings .ReplaceAll (s , "&" , `\&` )
97+ s = strings .ReplaceAll (s , "(" , `\(` )
98+ s = strings .ReplaceAll (s , ")" , `\)` )
99+ return s
100+ }
101+
93102// ExpandLiteral is a wrapper around [expand.Literal]. It will escape the input
94103// string, expand any shell symbols (such as '~') and resolve any environment
95104// variables.
@@ -115,6 +124,7 @@ func ExpandLiteral(s string) (string, error) {
115124// variables. It also expands brace expressions ({a.b}) and globs (*/**) and
116125// returns the results as a list of strings.
117126func ExpandFields (s string ) ([]string , error ) {
127+ s = escape (s )
118128 p := syntax .NewParser ()
119129 var words []* syntax.Word
120130 err := p .Words (strings .NewReader (s ), func (w * syntax.Word ) bool {
You can’t perform that action at this time.
0 commit comments