made is so things such as "/v1/users/" does not match "/v1/users/{user_id}"
parent
ebd12da522
commit
5a1e556549
|
@ -38,6 +38,10 @@ func (pattern *Pattern) Find(path string, args ...interface{}) (bool, error) {
|
|||
|
||||
s = s[len(bit):]
|
||||
case wildcardBit:
|
||||
if "" == s {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
index := strings.IndexRune(s, '/')
|
||||
|
||||
var value string
|
||||
|
|
|
@ -22,6 +22,26 @@ func TestPatternMatch(t *testing.T) {
|
|||
Path: "/v1/help/",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help",
|
||||
Path: "/v1/help/me",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help",
|
||||
Path: "/v1/help/me/",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help",
|
||||
Path: "/v1/helping",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help",
|
||||
Path: "/v1/helping/",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help",
|
||||
Path: "/v2/help",
|
||||
|
@ -60,6 +80,26 @@ func TestPatternMatch(t *testing.T) {
|
|||
Path: "/v1/help",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help/",
|
||||
Path: "/v1/help/me",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help/",
|
||||
Path: "/v1/help/me/",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help/",
|
||||
Path: "/v1/helping",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help/",
|
||||
Path: "/v1/helping/",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/help/",
|
||||
Path: "/v2/help/",
|
||||
|
@ -93,6 +133,11 @@ func TestPatternMatch(t *testing.T) {
|
|||
Path: "/v1/user/123",
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/user/{user_id}",
|
||||
Path: "/v1/user/",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/user/{user_id}",
|
||||
Path: "/v1/user/123/",
|
||||
|
@ -141,6 +186,11 @@ func TestPatternMatch(t *testing.T) {
|
|||
Path: "/v1/user/123/",
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/user/{user_id}/",
|
||||
Path: "/v1/user/",
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Pattern: "/v1/user/{user_id}/",
|
||||
Path: "/v1/user/123",
|
||||
|
|
Loading…
Reference in New Issue