cmd/go: do not ignore flags option with bad quoting

Fixes #43177

Change-Id: I7d8ef8dee0dcade3cc88fc6423e23f41d1f8ffb2
Reviewed-on: https://go-review.googlesource.com/c/go/+/339289
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
Mostafa Solati 2021-08-03 01:55:49 +04:30 committed by Gopher Robot
parent 6b6813fdb7
commit 97ce98ac20
2 changed files with 7 additions and 0 deletions

View file

@ -59,6 +59,9 @@ func (f *PerPackageFlag) set(v, cwd string) error {
if i == 0 {
return fmt.Errorf("missing <pattern> in <pattern>=<value>")
}
if v[0] == '\'' || v[0] == '"' {
return fmt.Errorf("parameter may not start with quote character %c", v[0])
}
pattern := strings.TrimSpace(v[:i])
match = MatchPackage(pattern, cwd)
v = v[i+1:]

View file

@ -34,6 +34,10 @@ stderr 'compile.* -p z3.* -e '
! go build -gcflags=-d=ssa/ z1
stderr 'PhaseOptions usage'
# check for valid -ldflags parameter
! go build '-ldflags="-X main.X=Hello"'
stderr 'invalid value'
# -ldflags for implicit test package applies to test binary
go test -c -n -gcflags=-N -ldflags=-X=x.y=z z1
stderr 'compile.* -N .*z_test.go'