From 03663480faa767e684bf17d7c45c65f79d7f5ef3 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 5 Oct 2016 14:42:45 -0400 Subject: [PATCH] go/buildutil: ExpandPatterns: ignore a trailing slash in a pattern Previously, a trailing slash would cause "foo/" to be treated as the name of a package, with comical results. Fixed golang/go#14584 Change-Id: I660f8a079bbd63d3645812e516a9264c8e080e61 Reviewed-on: https://go-review.googlesource.com/30452 Reviewed-by: Robert Griesemer --- go/buildutil/allpackages.go | 5 ++++- go/buildutil/allpackages_test.go | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/go/buildutil/allpackages.go b/go/buildutil/allpackages.go index 4d4366c1..c0cb03e7 100644 --- a/go/buildutil/allpackages.go +++ b/go/buildutil/allpackages.go @@ -137,6 +137,9 @@ func allPackages(ctxt *build.Context, root string, ch chan<- item) { // // encoding/... -encoding/xml // +// A trailing slash in a pattern is ignored. (Path components of Go +// package names are separated by slash, not the platform's path separator.) +// func ExpandPatterns(ctxt *build.Context, patterns []string) map[string]bool { // TODO(adonovan): support other features of 'go list': // - "std"/"cmd"/"all" meta-packages @@ -187,7 +190,7 @@ func ExpandPatterns(ctxt *build.Context, patterns []string) map[string]bool { } } else { // single package - doPkg(arg, neg) + doPkg(strings.TrimSuffix(arg, "/"), neg) } } diff --git a/go/buildutil/allpackages_test.go b/go/buildutil/allpackages_test.go index 96bf77a6..0440ff24 100644 --- a/go/buildutil/allpackages_test.go +++ b/go/buildutil/allpackages_test.go @@ -61,6 +61,8 @@ func TestExpandPatterns(t *testing.T) { {"...", "encoding encoding/hex encoding/json encoding/xml fmt"}, {"encoding/... -encoding/xml", "encoding encoding/hex encoding/json"}, {"... -encoding/...", "fmt"}, + {"encoding", "encoding"}, + {"encoding/", "encoding"}, } { var pkgs []string for pkg := range buildutil.ExpandPatterns(ctxt, strings.Fields(test.patterns)) {