From 2a7e19e0383430d75dcef9637c0c6dcaf64127d5 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 4 May 2018 15:43:50 -0700 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/go/internal/work/exec.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index fd607bfbd3..7379b886cc 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -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) -- 2.50.0