From 404c119a587288dc2af657ac747e21bbe406eb63 Mon Sep 17 00:00:00 2001 From: shouldsee Date: Tue, 14 Dec 2021 23:07:02 +0800 Subject: [PATCH] sh.run(): quoted strings before join (#306) * sh.run(): quoted strings before join Co-authored-by: shouldsee Co-authored-by: Nate Finch --- sh/cmd.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sh/cmd.go b/sh/cmd.go index 06af62de..87bb37e6 100644 --- a/sh/cmd.go +++ b/sh/cmd.go @@ -132,11 +132,15 @@ func run(env map[string]string, stdout, stderr io.Writer, cmd string, args ...st c.Stderr = stderr c.Stdout = stdout c.Stdin = os.Stdin - log.Println("exec:", cmd, strings.Join(args, " ")) + + var quoted []string + for i := range args { + quoted = append(quoted, fmt.Sprintf("%q", args[i])); + } + log.Println("exec:", cmd, strings.Join(quoted, " ")) err = c.Run() return CmdRan(err), ExitStatus(err), err } - // CmdRan examines the error to determine if it was generated as a result of a // command running via os/exec.Command. If the error is nil, or the command ran // (even if it exited with a non-zero exit code), CmdRan reports true. If the