From b3c4007756dff95574def1420777eff85799d89f Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Mon, 28 Apr 2025 13:02:46 +0100 Subject: [PATCH] fix: double escaped paths (#2216) --- internal/execext/exec.go | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/internal/execext/exec.go b/internal/execext/exec.go index 811d539c..49af5249 100644 --- a/internal/execext/exec.go +++ b/internal/execext/exec.go @@ -90,15 +90,6 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error { return r.Run(ctx, p) } -func escape(s string) string { - s = filepath.ToSlash(s) - s = strings.ReplaceAll(s, " ", `\ `) - s = strings.ReplaceAll(s, "&", `\&`) - s = strings.ReplaceAll(s, "(", `\(`) - s = strings.ReplaceAll(s, ")", `\)`) - return s -} - // ExpandLiteral is a wrapper around [expand.Literal]. It will escape the input // string, expand any shell symbols (such as '~') and resolve any environment // variables. @@ -106,25 +97,17 @@ func ExpandLiteral(s string) (string, error) { if s == "" { return "", nil } - s = escape(s) p := syntax.NewParser() - var words []*syntax.Word - err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool { - words = append(words, w) - return true - }) + word, err := p.Document(strings.NewReader(s)) if err != nil { return "", err } - if len(words) == 0 { - return "", nil - } cfg := &expand.Config{ Env: expand.FuncEnviron(os.Getenv), ReadDir2: os.ReadDir, GlobStar: true, } - return expand.Literal(cfg, words[0]) + return expand.Literal(cfg, word) } // ExpandFields is a wrapper around [expand.Fields]. It will escape the input @@ -132,7 +115,6 @@ func ExpandLiteral(s string) (string, error) { // variables. It also expands brace expressions ({a.b}) and globs (*/**) and // returns the results as a list of strings. func ExpandFields(s string) ([]string, error) { - s = escape(s) p := syntax.NewParser() var words []*syntax.Word err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool {