Merge pull request #136 from cboylan/fix-vendor-regex

Fix IsVendor() regex generation
This commit is contained in:
Alex 2022-10-06 09:41:27 +02:00 committed by GitHub
commit a53744636a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -213,23 +213,23 @@ func init() {
sb := &strings.Builder{}
// Start with group 1 - those that started with `^`
sb.WriteString("(?:^(?:")
sb.WriteString("(?:^(?:(?:")
sb.WriteString(caretStrings[0])
for _, matcher := range caretStrings[1:] {
sb.WriteString(")|(?:")
sb.WriteString(matcher)
}
sb.WriteString("))")
sb.WriteString(")))")
sb.WriteString("|")
// Now add group 2 - those that started with `(^|/)`
sb.WriteString("(?:(?:^|/)(?:")
sb.WriteString("(?:(?:^|/)(?:(?:")
sb.WriteString(caretSegmentStrings[0])
for _, matcher := range caretSegmentStrings[1:] {
sb.WriteString(")|(?:")
sb.WriteString(matcher)
}
sb.WriteString("))")
sb.WriteString(")))")
sb.WriteString("|")
// Finally add the rest

View File

@ -17,6 +17,7 @@ func TestIsVendor(t *testing.T) {
expected bool
}{
{"cache/", true},
{"something_cache/", false},
{"random/cache/", true},
{"cache", false},
{"dependencies/", true},
@ -27,6 +28,7 @@ func TestIsVendor(t *testing.T) {
{"random/dist/", true},
{"random/dist", false},
{"deps/", true},
{"foodeps/", false},
{"configure", true},
{"a/configure", true},
{"config.guess", true},
@ -43,6 +45,7 @@ func TestIsVendor(t *testing.T) {
{"foo/bar/MochiKit.js", true},
{"foo/bar/dojo.js", true},
{"foo/env/whatever", true},
{"some/python/venv/", false},
{"foo/.imageset/bar", true},
{"Vagrantfile", true},
}