Skip to content

Commit d2bd834

Browse files
authored
fix: spaces in path (#2322)
1 parent 8a43ca5 commit d2bd834

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

internal/execext/exec.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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.
117126
func 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 {

0 commit comments

Comments
 (0)