Skip to content

Commit

Permalink
cmd/go: do not ignore flags option with bad quoting
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mostafasolati authored and gopherbot committed May 19, 2022
1 parent 6b6813f commit 97ce98a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cmd/go/internal/load/flag.go
Expand Up @@ -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:]
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/go/testdata/script/gcflags_patterns.txt
Expand Up @@ -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'
Expand Down

0 comments on commit 97ce98a

Please sign in to comment.