@@ -123,9 +123,6 @@ func (e *Engine) runCommand(ctx Context, tool types.Tool, input string, toolCate
123
123
}
124
124
cmd , stop , err := e .newCommand (ctx .Ctx , extraEnv , tool , input )
125
125
if err != nil {
126
- if toolCategory == NoCategory {
127
- return fmt .Sprintf ("ERROR: got (%v) while parsing command" , err ), nil
128
- }
129
126
return "" , err
130
127
}
131
128
defer stop ()
@@ -271,12 +268,6 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, tool types.T
271
268
})
272
269
}
273
270
274
- // After we determined the interpreter we again interpret the args by env vars
275
- args , err = replaceVariablesForInterpreter (interpreter , envMap )
276
- if err != nil {
277
- return nil , nil , err
278
- }
279
-
280
271
if runtime .GOOS == "windows" && (args [0 ] == "/bin/bash" || args [0 ] == "/bin/sh" ) {
281
272
args [0 ] = path .Base (args [0 ])
282
273
}
@@ -323,87 +314,3 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, tool types.T
323
314
cmd .Env = compressEnv (envvars )
324
315
return cmd , stop , nil
325
316
}
326
-
327
- func replaceVariablesForInterpreter (interpreter string , envMap map [string ]string ) ([]string , error ) {
328
- var parts []string
329
- for i , part := range splitByQuotes (interpreter ) {
330
- if i % 2 == 0 {
331
- part = os .Expand (part , func (s string ) string {
332
- return envMap [s ]
333
- })
334
- // We protect newly resolved env vars from getting replaced when we do the second Expand
335
- // after shlex. Yeah, crazy. I'm guessing this isn't secure, but just trying to avoid a foot gun.
336
- part = os .Expand (part , func (s string ) string {
337
- return "${__" + s + "}"
338
- })
339
- }
340
- parts = append (parts , part )
341
- }
342
-
343
- parts , err := shlex .Split (strings .Join (parts , "" ))
344
- if err != nil {
345
- return nil , err
346
- }
347
-
348
- for i , part := range parts {
349
- parts [i ] = os .Expand (part , func (s string ) string {
350
- if strings .HasPrefix (s , "__" ) {
351
- return "${" + s [2 :] + "}"
352
- }
353
- return envMap [s ]
354
- })
355
- }
356
-
357
- return parts , nil
358
- }
359
-
360
- // splitByQuotes will split a string by parsing matching double quotes (with \ as the escape character).
361
- // The return value conforms to the following properties
362
- // 1. s == strings.Join(result, "")
363
- // 2. Even indexes are strings that were not in quotes.
364
- // 3. Odd indexes are strings that were quoted.
365
- //
366
- // Example: s = `In a "quoted string" quotes can be escaped with \"`
367
- //
368
- // result = [`In a `, `"quoted string"`, ` quotes can be escaped with \"`]
369
- func splitByQuotes (s string ) (result []string ) {
370
- var (
371
- buf strings.Builder
372
- inEscape , inQuote bool
373
- )
374
-
375
- for _ , c := range s {
376
- if inEscape {
377
- buf .WriteRune (c )
378
- inEscape = false
379
- continue
380
- }
381
-
382
- switch c {
383
- case '"' :
384
- if inQuote {
385
- buf .WriteRune (c )
386
- }
387
- result = append (result , buf .String ())
388
- buf .Reset ()
389
- if ! inQuote {
390
- buf .WriteRune (c )
391
- }
392
- inQuote = ! inQuote
393
- case '\\' :
394
- inEscape = true
395
- buf .WriteRune (c )
396
- default :
397
- buf .WriteRune (c )
398
- }
399
- }
400
-
401
- if buf .Len () > 0 {
402
- if inQuote {
403
- result = append (result , "" )
404
- }
405
- result = append (result , buf .String ())
406
- }
407
-
408
- return
409
- }
0 commit comments