mirror of https://github.com/golang/go.git
cmd/go: refuse -w with an invalid GOPATH
Fixes #35338 Change-Id: Ic2a3a446ef56b1e5723d6192c8aeec32ae0bbeac Reviewed-on: https://go-review.googlesource.com/c/go/+/205779 Run-TryBot: Baokun Lee <nototon@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
e6c12c3d02
commit
f6ff806e48
|
|
@ -353,6 +353,13 @@ func checkEnvWrite(key, val string) error {
|
|||
default:
|
||||
return fmt.Errorf("invalid %s value %q", key, val)
|
||||
}
|
||||
case "GOPATH":
|
||||
if strings.HasPrefix(val, "~") {
|
||||
return fmt.Errorf("GOPATH entry cannot start with shell metacharacter '~': %q", val)
|
||||
}
|
||||
if !filepath.IsAbs(val) && val != "" {
|
||||
return fmt.Errorf("GOPATH entry is relative; must be absolute path: %q", val)
|
||||
}
|
||||
}
|
||||
|
||||
if !utf8.ValidString(val) {
|
||||
|
|
|
|||
|
|
@ -89,3 +89,10 @@ stderr 'arguments must be KEY=VALUE: invalid argument: GOOS'
|
|||
# go env -w rejects invalid GO111MODULE values, as otherwise cmd/go would break
|
||||
! go env -w GO111MODULE=badvalue
|
||||
stderr 'invalid GO111MODULE value "badvalue"'
|
||||
|
||||
# go env -w rejects invalid GOPATH values
|
||||
! go env -w GOPATH=~/go
|
||||
stderr 'GOPATH entry cannot start with shell metacharacter'
|
||||
|
||||
! go env -w GOPATH=./go
|
||||
stderr 'GOPATH entry is relative; must be absolute path'
|
||||
|
|
|
|||
Loading…
Reference in New Issue