module: accept trailing slash in MatchPrefixPattern
Trailing slash of glob was not accepted in MatchPrefixPattern. This
CL starts to accept the trailing slash.
Change-Id: I25e385ffe3a6901d2f475b86507d3e3091a32183
GitHub-Last-Rev: 5dbe41e5458d405a30ff82521316c6ab5e90835d
GitHub-Pull-Request: golang/mod#5
Reviewed-on: https://go-review.googlesource.com/c/mod/+/351319
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
diff --git a/module/module.go b/module/module.go
index 89bd3ed..355b5a4 100644
--- a/module/module.go
+++ b/module/module.go
@@ -798,6 +798,7 @@
// GOPRIVATE environment variable, as described by 'go help module-private'.
//
// It ignores any empty or malformed patterns in the list.
+// Trailing slashes on patterns are ignored.
func MatchPrefixPatterns(globs, target string) bool {
for globs != "" {
// Extract next non-empty glob in comma-separated list.
@@ -807,6 +808,7 @@
} else {
glob, globs = globs, ""
}
+ glob = strings.TrimSuffix(glob, "/")
if glob == "" {
continue
}
diff --git a/module/module_test.go b/module/module_test.go
index 2cfb7aa..4d79daa 100644
--- a/module/module_test.go
+++ b/module/module_test.go
@@ -353,6 +353,8 @@
globs, target string
want bool
}{
+ {"", "rsc.io/quote", false},
+ {"/", "rsc.io/quote", false},
{"*/quote", "rsc.io/quote", true},
{"*/quo", "rsc.io/quote", false},
{"*/quo??", "rsc.io/quote", true},
@@ -360,17 +362,21 @@
{"*quo*", "rsc.io/quote", false},
{"rsc.io", "rsc.io/quote", true},
{"*.io", "rsc.io/quote", true},
- {"rsc.io/", "rsc.io/quote", false},
+ {"rsc.io/", "rsc.io/quote", true},
{"rsc", "rsc.io/quote", false},
{"rsc*", "rsc.io/quote", true},
{"rsc.io", "rsc.io/quote/v3", true},
{"*/quote", "rsc.io/quote/v3", true},
+ {"*/quote/", "rsc.io/quote/v3", true},
{"*/quote/*", "rsc.io/quote/v3", true},
+ {"*/quote/*/", "rsc.io/quote/v3", true},
{"*/v3", "rsc.io/quote/v3", false},
{"*/*/v3", "rsc.io/quote/v3", true},
{"*/*/*", "rsc.io/quote/v3", true},
+ {"*/*/*/", "rsc.io/quote/v3", true},
{"*/*/*", "rsc.io/quote", false},
+ {"*/*/*/", "rsc.io/quote", false},
{"*/*/*,,", "rsc.io/quote", false},
{"*/*/*,,*/quote", "rsc.io/quote", true},