mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: allow project names with dots for badges (resolve #301)
This commit is contained in:
parent
8e6719f0b7
commit
e967a74e36
@ -17,7 +17,7 @@ import (
|
||||
|
||||
const (
|
||||
intervalPattern = `interval:([a-z0-9_]+)`
|
||||
entityFilterPattern = `(project|os|editor|language|machine|label):([_a-zA-Z0-9-\s]+)`
|
||||
entityFilterPattern = `(project|os|editor|language|machine|label):([_a-zA-Z0-9-\s\.]+)`
|
||||
)
|
||||
|
||||
type BadgeHandler struct {
|
||||
|
43
routes/compat/shields/v1/badge_test.go
Normal file
43
routes/compat/shields/v1/badge_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBadgeHandler_EntityPattern(t *testing.T) {
|
||||
type test struct {
|
||||
test string
|
||||
key string
|
||||
val string
|
||||
}
|
||||
|
||||
pathPrefix := "/compat/shields/v1/current/today/"
|
||||
|
||||
tests := []test{
|
||||
{test: pathPrefix + "project:wakapi", key: "project", val: "wakapi"},
|
||||
{test: pathPrefix + "os:Linux", key: "os", val: "Linux"},
|
||||
{test: pathPrefix + "editor:VSCode", key: "editor", val: "VSCode"},
|
||||
{test: pathPrefix + "language:Java", key: "language", val: "Java"},
|
||||
{test: pathPrefix + "machine:devmachine", key: "machine", val: "devmachine"},
|
||||
{test: pathPrefix + "label:work", key: "label", val: "work"},
|
||||
{test: pathPrefix + "foo:bar", key: "", val: ""}, // invalid entity
|
||||
{test: pathPrefix + "project:01234", key: "project", val: "01234"}, // digits only
|
||||
{test: pathPrefix + "project:anchr-web-ext", key: "project", val: "anchr-web-ext"}, // with dashes
|
||||
{test: pathPrefix + "project:wakapi v2", key: "project", val: "wakapi v2"}, // with blank space
|
||||
{test: pathPrefix + "project:project", key: "project", val: "project"},
|
||||
{test: pathPrefix + "project:Anchr-Android_v2.0", key: "project", val: "Anchr-Android_v2.0"}, // all the way
|
||||
}
|
||||
|
||||
sut := regexp.MustCompile(entityFilterPattern)
|
||||
|
||||
for _, tc := range tests {
|
||||
var key, val string
|
||||
if groups := sut.FindStringSubmatch(tc.test); len(groups) > 2 {
|
||||
key, val = groups[1], groups[2]
|
||||
}
|
||||
assert.Equal(t, tc.key, key)
|
||||
assert.Equal(t, tc.val, val)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user