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: 5dbe41e545
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>
This commit is contained in:
Родитель
37dd689102
Коммит
dd30a601dd
|
@ -798,6 +798,7 @@ func unescapeString(escaped string) (string, bool) {
|
|||
// 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 @@ func MatchPrefixPatterns(globs, target string) bool {
|
|||
} else {
|
||||
glob, globs = globs, ""
|
||||
}
|
||||
glob = strings.TrimSuffix(glob, "/")
|
||||
if glob == "" {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -353,6 +353,8 @@ func TestMatchPrefixPatterns(t *testing.T) {
|
|||
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 @@ func TestMatchPrefixPatterns(t *testing.T) {
|
|||
{"*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},
|
||||
|
|
Загрузка…
Ссылка в новой задаче