mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
fix: double escaped paths (#2216)
This commit is contained in:
@@ -90,15 +90,6 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
|
|||||||
return r.Run(ctx, p)
|
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
|
// ExpandLiteral is a wrapper around [expand.Literal]. It will escape the input
|
||||||
// string, expand any shell symbols (such as '~') and resolve any environment
|
// string, expand any shell symbols (such as '~') and resolve any environment
|
||||||
// variables.
|
// variables.
|
||||||
@@ -106,25 +97,17 @@ func ExpandLiteral(s string) (string, error) {
|
|||||||
if s == "" {
|
if s == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
s = escape(s)
|
|
||||||
p := syntax.NewParser()
|
p := syntax.NewParser()
|
||||||
var words []*syntax.Word
|
word, err := p.Document(strings.NewReader(s))
|
||||||
err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool {
|
|
||||||
words = append(words, w)
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if len(words) == 0 {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
cfg := &expand.Config{
|
cfg := &expand.Config{
|
||||||
Env: expand.FuncEnviron(os.Getenv),
|
Env: expand.FuncEnviron(os.Getenv),
|
||||||
ReadDir2: os.ReadDir,
|
ReadDir2: os.ReadDir,
|
||||||
GlobStar: true,
|
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
|
// 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
|
// variables. It also expands brace expressions ({a.b}) and globs (*/**) and
|
||||||
// returns the results as a list of strings.
|
// returns the results as a list of strings.
|
||||||
func ExpandFields(s string) ([]string, error) {
|
func ExpandFields(s string) ([]string, error) {
|
||||||
s = escape(s)
|
|
||||||
p := syntax.NewParser()
|
p := syntax.NewParser()
|
||||||
var words []*syntax.Word
|
var words []*syntax.Word
|
||||||
err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool {
|
err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool {
|
||||||
|
Reference in New Issue
Block a user