From 5a1e556549f470ec14df0e05a52ad3ac420b19d8 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Mon, 24 Jun 2019 15:04:02 -0700 Subject: [PATCH] made is so things such as "/v1/users/" does not match "/v1/users/{user_id}" --- pattern_find.go | 4 ++++ pattern_match_test.go | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/pattern_find.go b/pattern_find.go index a0e16a3..b41ba09 100644 --- a/pattern_find.go +++ b/pattern_find.go @@ -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 diff --git a/pattern_match_test.go b/pattern_match_test.go index ecacd60..0063f3d 100644 --- a/pattern_match_test.go +++ b/pattern_match_test.go @@ -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",