made is so things such as "/v1/users/" does not match "/v1/users/{user_id}"

master
Charles Iliya Krempeaux 2019-06-24 15:04:02 -07:00
parent ebd12da522
commit 5a1e556549
2 changed files with 54 additions and 0 deletions

View File

@ -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

View File

@ -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",