diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index a64bbf495..a1ee0b6e1 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -290,22 +290,10 @@ func (t *ExecTool) guardCommand(command, cwd string) string { return "" } - // Match absolute paths: Unix (starts with /) or Windows (X:\) - pathPattern := regexp.MustCompile(`(?:\s|^|["'|&;])(/[^\s\"'|&;:]+)|([A-Za-z]:\\[^\\\"'|&;:]+)`) - matches := pathPattern.FindAllStringSubmatch(cmd, -1) - - for _, match := range matches { - raw := "" - if match[1] != "" { - raw = match[1] // Unix path - } else if match[2] != "" { - raw = match[2] // Windows path - } - - if raw == "" { - continue - } + pathPattern := regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`) + matches := pathPattern.FindAllString(cmd, -1) + for _, raw := range matches { p, err := filepath.Abs(raw) if err != nil { continue