From: miller Date: Mon, 8 May 2023 15:56:21 +0000 (+0100) Subject: cmd/go: quote entries in list-valued variables for go env in plan9 X-Git-Tag: go1.21rc1~267 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=05cc9e55876874462a4726ca0101c970838c80e5;p=gostls13.git cmd/go: quote entries in list-valued variables for go env in plan9 When 'go env' without an argument prints environment variables as a script which can be executed by the shell, variables with a list value in Plan 9 (such as GOPATH) need to be printed with each element enclosed in single quotes in case it contains characters significant to the Plan 9 shell (such as ' ' or '='). For #58508 Change-Id: Ia30f51307cc6d07a7e3ada6bf9d60bf9951982ff Reviewed-on: https://go-review.googlesource.com/c/go/+/493535 Run-TryBot: Cherry Mui Reviewed-by: Cherry Mui Reviewed-by: Russ Cox TryBot-Result: Gopher Robot Auto-Submit: Dmitri Shuralyov --- diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go index 74c0b69629..b99176f939 100644 --- a/src/cmd/go/internal/envcmd/env.go +++ b/src/cmd/go/internal/envcmd/env.go @@ -435,8 +435,7 @@ func PrintEnv(w io.Writer, env []cfg.EnvVar) { if x > 0 { fmt.Fprintf(w, " ") } - // TODO(#59979): Does this need to be quoted like above? - fmt.Fprintf(w, "%s", s) + fmt.Fprintf(w, "'%s'", strings.ReplaceAll(s, "'", "''")) } fmt.Fprintf(w, ")\n") }