Commit 2a7e19e0 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/go: quote parentheses when outputting command

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent d0ed8d6e
...@@ -1580,7 +1580,9 @@ func joinUnambiguously(a []string) string { ...@@ -1580,7 +1580,9 @@ func joinUnambiguously(a []string) string {
buf.WriteByte(' ') buf.WriteByte(' ')
} }
q := strconv.Quote(s) 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) buf.WriteString(q)
} else { } else {
buf.WriteString(s) buf.WriteString(s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment