]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: quote parentheses when outputting command
authorIan Lance Taylor <iant@golang.org>
Fri, 4 May 2018 22:43:50 +0000 (15:43 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 5 May 2018 00:53:45 +0000 (00:53 +0000)
A gccgo command line can contain parentheses, for -( and -).
Quote them when outputting a command line, so that `go build -x`
output is suitable for use as shell input.

Change-Id: I43194b87bf048e583c222b19ca4bcdcb1deca97a
Reviewed-on: https://go-review.googlesource.com/111635
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/internal/work/exec.go

index fd607bfbd360a9f9ac99ae5b749b8fa9bc4bfddf..7379b886cc7ff6f3f4a6ccac03c92ce0241e8f7f 100644 (file)
@@ -1580,7 +1580,9 @@ func joinUnambiguously(a []string) string {
                        buf.WriteByte(' ')
                }
                q := strconv.Quote(s)
-               if s == "" || strings.Contains(s, " ") || len(q) > len(s)+2 {
+               // A gccgo command line can contain -( and -).
+               // Make sure we quote them since they are special to the shell.
+               if s == "" || strings.ContainsAny(s, " ()") || len(q) > len(s)+2 {
                        buf.WriteString(q)
                } else {
                        buf.WriteString(s)