@@ -90,49 +90,31 @@ 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-
10293// ExpandLiteral is a wrapper around [expand.Literal]. It will escape the input
10394// string, expand any shell symbols (such as '~') and resolve any environment
10495// variables.
10596func ExpandLiteral (s string ) (string , error ) {
10697 if s == "" {
10798 return "" , nil
10899 }
109- s = escape (s )
110100 p := syntax .NewParser ()
111- var words []* syntax.Word
112- err := p .Words (strings .NewReader (s ), func (w * syntax.Word ) bool {
113- words = append (words , w )
114- return true
115- })
101+ word , err := p .Document (strings .NewReader (s ))
116102 if err != nil {
117103 return "" , err
118104 }
119- if len (words ) == 0 {
120- return "" , nil
121- }
122105 cfg := & expand.Config {
123106 Env : expand .FuncEnviron (os .Getenv ),
124107 ReadDir2 : os .ReadDir ,
125108 GlobStar : true ,
126109 }
127- return expand .Literal (cfg , words [ 0 ] )
110+ return expand .Literal (cfg , word )
128111}
129112
130113// ExpandFields is a wrapper around [expand.Fields]. It will escape the input
131114// string, expand any shell symbols (such as '~') and resolve any environment
132115// variables. It also expands brace expressions ({a.b}) and globs (*/**) and
133116// returns the results as a list of strings.
134117func ExpandFields (s string ) ([]string , error ) {
135- s = escape (s )
136118 p := syntax .NewParser ()
137119 var words []* syntax.Word
138120 err := p .Words (strings .NewReader (s ), func (w * syntax.Word ) bool {
0 commit comments