]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: quote entries in list-valued variables for go env in plan9
authormiller <millerresearch@gmail.com>
Mon, 8 May 2023 15:56:21 +0000 (16:56 +0100)
committerGopher Robot <gobot@golang.org>
Wed, 24 May 2023 21:48:53 +0000 (21:48 +0000)
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 <cherryyz@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>

src/cmd/go/internal/envcmd/env.go

index 74c0b69629baf5d608ed595715cabcdf9bb9270d..b99176f939d29cb78b21ae36c3725344c6b0d2aa 100644 (file)
@@ -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")
                                }