Skip to content

Commit

Permalink
Merge pull request fagongzi#206 from rrylee/hotfix/find_routeAdd
Browse files Browse the repository at this point in the history
修复路由添加错误
  • Loading branch information
zhangxu19830126 authored Mar 17, 2020
2 parents f790779 + 27515a8 commit 9abd2d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *Route) Add(api *metapb.API) error {
parent := r.root
matchedIdx := 0
for idx, node := range nodes {
if parent.matches(node) {
if idx == 0 && parent.matches(node) {
matchedIdx = idx
continue
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ func TestAdd(t *testing.T) {
if len(r.root.children) != 5 {
t.Errorf("expect 4 children but %d, %+v", len(r.root.children), r.root)
}

r.Add(&metapb.API{
ID: 6,
URLPattern: "/a/b/b/a",
Method: "*",
})
r.Add(&metapb.API{
ID: 7,
URLPattern: "/a/b/b/c",
Method: "*",
})
_, ok := r.Find([]byte("/a/b/b/c"), "*", nil)
if !ok {
t.Errorf("expected match /a/b/b/c, but not")
}
}

func TestFindWithStar(t *testing.T) {
Expand Down

0 comments on commit 9abd2d1

Please sign in to comment.