mirror of
https://github.com/golang/go.git
synced 2025-05-18 22:04:38 +00:00
cmd/go: ignore GOFLAGS values without name in go env/bug
This happens with 'go env' and 'go bug'. If GOFLAGS variable is set to something like '=value', running `go env` panics with this error message: goroutine 1 [running]: cmd/go/internal/base.SetFromGOFLAGS(0xd96838) cmd/go/internal/base/goflags.go:101 +0x9a7 main.main() cmd/go/main.go:188 +0x755 This happens when the 'name' of the flag is not specified ('=' or '=value'), with any combination of other flags. Other commands show this error message: go: parsing $GOFLAGS: non-flag This happens only with 'env' and 'bug' because we have this: https://go.googlesource.com/go/+/refs/heads/master/src/cmd/go/internal/base/goflags.go#40 New behaviour: ignore the bad flag, since we don't want to report that with `go env` or `go bug`. Fixes: #42013 Change-Id: I72602840ca00293d2a92ea28451b75b9799e3d6c Reviewed-on: https://go-review.googlesource.com/c/go/+/263098 Reviewed-by: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
15ead857db
commit
bcc3333487
@ -92,7 +92,11 @@ func SetFromGOFLAGS(flags *flag.FlagSet) {
|
|||||||
}
|
}
|
||||||
for _, goflag := range goflags {
|
for _, goflag := range goflags {
|
||||||
name, value, hasValue := goflag, "", false
|
name, value, hasValue := goflag, "", false
|
||||||
if i := strings.Index(goflag, "="); i >= 0 {
|
// Ignore invalid flags like '=' or '=value'.
|
||||||
|
// If it is not reported in InitGOFlags it means we don't want to report it.
|
||||||
|
if i := strings.Index(goflag, "="); i == 0 {
|
||||||
|
continue
|
||||||
|
} else if i > 0 {
|
||||||
name, value, hasValue = goflag[:i], goflag[i+1:], true
|
name, value, hasValue = goflag[:i], goflag[i+1:], true
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "--") {
|
if strings.HasPrefix(name, "--") {
|
||||||
|
4
src/cmd/go/testdata/script/env_write.txt
vendored
4
src/cmd/go/testdata/script/env_write.txt
vendored
@ -24,6 +24,10 @@ stdout GOARCH=
|
|||||||
stdout GOOS=
|
stdout GOOS=
|
||||||
stdout GOROOT=
|
stdout GOROOT=
|
||||||
|
|
||||||
|
# go env ignores invalid flag in GOFLAGS environment variable
|
||||||
|
env GOFLAGS='=true'
|
||||||
|
go env
|
||||||
|
|
||||||
# checking errors
|
# checking errors
|
||||||
! go env -w
|
! go env -w
|
||||||
stderr 'go env -w: no KEY=VALUE arguments given'
|
stderr 'go env -w: no KEY=VALUE arguments given'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user