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):]
|
s = s[len(bit):]
|
||||||
case wildcardBit:
|
case wildcardBit:
|
||||||
|
if "" == s {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
index := strings.IndexRune(s, '/')
|
index := strings.IndexRune(s, '/')
|
||||||
|
|
||||||
var value string
|
var value string
|
||||||
|
|
|
@ -22,6 +22,26 @@ func TestPatternMatch(t *testing.T) {
|
||||||
Path: "/v1/help/",
|
Path: "/v1/help/",
|
||||||
Expected: false,
|
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",
|
Pattern: "/v1/help",
|
||||||
Path: "/v2/help",
|
Path: "/v2/help",
|
||||||
|
@ -60,6 +80,26 @@ func TestPatternMatch(t *testing.T) {
|
||||||
Path: "/v1/help",
|
Path: "/v1/help",
|
||||||
Expected: false,
|
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/",
|
Pattern: "/v1/help/",
|
||||||
Path: "/v2/help/",
|
Path: "/v2/help/",
|
||||||
|
@ -93,6 +133,11 @@ func TestPatternMatch(t *testing.T) {
|
||||||
Path: "/v1/user/123",
|
Path: "/v1/user/123",
|
||||||
Expected: true,
|
Expected: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Pattern: "/v1/user/{user_id}",
|
||||||
|
Path: "/v1/user/",
|
||||||
|
Expected: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Pattern: "/v1/user/{user_id}",
|
Pattern: "/v1/user/{user_id}",
|
||||||
Path: "/v1/user/123/",
|
Path: "/v1/user/123/",
|
||||||
|
@ -141,6 +186,11 @@ func TestPatternMatch(t *testing.T) {
|
||||||
Path: "/v1/user/123/",
|
Path: "/v1/user/123/",
|
||||||
Expected: true,
|
Expected: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Pattern: "/v1/user/{user_id}/",
|
||||||
|
Path: "/v1/user/",
|
||||||
|
Expected: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Pattern: "/v1/user/{user_id}/",
|
Pattern: "/v1/user/{user_id}/",
|
||||||
Path: "/v1/user/123",
|
Path: "/v1/user/123",
|
||||||
|
|
Loading…
Reference in New Issue