Commit 5361712a authored by Maxim Pimenov's avatar Maxim Pimenov Committed by Russ Cox

go/build: fix match

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5801043
parent cc99d8ad
...@@ -874,7 +874,7 @@ func splitQuoted(s string) (r []string, err error) { ...@@ -874,7 +874,7 @@ func splitQuoted(s string) (r []string, err error) {
// !cgo (if cgo is disabled) // !cgo (if cgo is disabled)
// tag (if tag is listed in ctxt.BuildTags) // tag (if tag is listed in ctxt.BuildTags)
// !tag (if tag is not listed in ctxt.BuildTags) // !tag (if tag is not listed in ctxt.BuildTags)
// a slash-separated list of any of these // a comma-separated list of any of these
// //
func (ctxt *Context) match(name string) bool { func (ctxt *Context) match(name string) bool {
if name == "" { if name == "" {
...@@ -888,11 +888,11 @@ func (ctxt *Context) match(name string) bool { ...@@ -888,11 +888,11 @@ func (ctxt *Context) match(name string) bool {
return false return false
} }
if strings.HasPrefix(name, "!") { // negation if strings.HasPrefix(name, "!") { // negation
return !ctxt.match(name[1:]) return len(name) > 1 && !ctxt.match(name[1:])
} }
// Tags must be letters, digits, underscores. // Tags must be letters, digits, underscores.
// Unlike in Go identifiers, all digits is fine (e.g., "386"). // Unlike in Go identifiers, all digits are fine (e.g., "386").
for _, c := range name { for _, c := range name {
if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' { if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' {
return false return false
......
...@@ -36,6 +36,7 @@ func TestMatch(t *testing.T) { ...@@ -36,6 +36,7 @@ func TestMatch(t *testing.T) {
nomatch(runtime.GOOS + "," + runtime.GOARCH + ",!foo") nomatch(runtime.GOOS + "," + runtime.GOARCH + ",!foo")
match(runtime.GOOS + "," + runtime.GOARCH + ",!bar") match(runtime.GOOS + "," + runtime.GOARCH + ",!bar")
nomatch(runtime.GOOS + "," + runtime.GOARCH + ",bar") nomatch(runtime.GOOS + "," + runtime.GOARCH + ",bar")
nomatch("!")
} }
func TestDotSlashImport(t *testing.T) { func TestDotSlashImport(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment