diff --git a/pkg/route/route.go b/pkg/route/route.go index 0ceb85a2..e8487d73 100644 --- a/pkg/route/route.go +++ b/pkg/route/route.go @@ -178,8 +178,14 @@ func (r *Route) Find(url []byte, method string, paramsFunc func(name, value []by OUTER: for idx, node := range nodes { + ok := false for _, item := range target { - if item.urlMatches(node, &matchAllParams) { + ok = item.urlMatches(node, &matchAllParams) + log.Infof(">>>>>>>>>> %s matches %s: %+v", + string(item.node.value), + string(node.value), + ok) + if ok { matchedIdx = idx matchesItem = item if item.node.hasArg && paramsFunc != nil { @@ -193,6 +199,11 @@ OUTER: continue OUTER } } + log.Infof("check next item") + + if !ok { + return 0, false + } } if matchedIdx == len(nodes)-1 { diff --git a/pkg/route/route_test.go b/pkg/route/route_test.go index a8ba4069..ae15cfb3 100644 --- a/pkg/route/route_test.go +++ b/pkg/route/route_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/fagongzi/gateway/pkg/pb/metapb" + "github.com/stretchr/testify/assert" ) func TestAddWithMethod(t *testing.T) { @@ -337,3 +338,24 @@ func TestFind(t *testing.T) { t.Errorf("expect not matched , but %d", id) } } + +func TestIssue225(t *testing.T) { + domain1 := "baidu.com" + params := make(map[string][]byte) + paramsFunc := func(name, value []byte) { + params[string(name)] = value + } + + r := NewRoute() + r.Add(&metapb.API{ + ID: 1, + MatchRule: metapb.MatchAll, + URLPattern: "/a/b/c", + Method: "POST", + Domain: domain1, + }) + + id, ok := r.Find([]byte("/a/b/d/c"), "POST", paramsFunc) + assert.False(t, ok) + assert.Equal(t, uint64(0), id) +}