mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 03:01:28 +00:00
fix static pattern match for leaf
This commit is contained in:
parent
f45b271b96
commit
90e7d252a7
2
tree.go
2
tree.go
@ -389,7 +389,7 @@ type leafInfo struct {
|
|||||||
func (leaf *leafInfo) match(wildcardValues []string, ctx *context.Context) (ok bool) {
|
func (leaf *leafInfo) match(wildcardValues []string, ctx *context.Context) (ok bool) {
|
||||||
//fmt.Println("Leaf:", wildcardValues, leaf.wildcards, leaf.regexps)
|
//fmt.Println("Leaf:", wildcardValues, leaf.wildcards, leaf.regexps)
|
||||||
if leaf.regexps == nil {
|
if leaf.regexps == nil {
|
||||||
if len(wildcardValues) == 0 { // static path
|
if len(wildcardValues) == 0 && len(leaf.wildcards) == 0 { // static path
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match *
|
// match *
|
||||||
|
15
tree_test.go
15
tree_test.go
@ -97,6 +97,21 @@ func TestTreeRouters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStaticPath(t *testing.T) {
|
||||||
|
tr := NewTree()
|
||||||
|
tr.AddRouter("/topic/:id", "wildcard")
|
||||||
|
tr.AddRouter("/topic", "static")
|
||||||
|
ctx := context.NewContext()
|
||||||
|
obj := tr.Match("/topic", ctx)
|
||||||
|
if obj == nil || obj.(string) != "static" {
|
||||||
|
t.Fatal("/topic is a static route")
|
||||||
|
}
|
||||||
|
obj = tr.Match("/topic/1", ctx)
|
||||||
|
if obj == nil || obj.(string) != "wildcard" {
|
||||||
|
t.Fatal("/topic/1 is a wildcard route")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddTree(t *testing.T) {
|
func TestAddTree(t *testing.T) {
|
||||||
tr := NewTree()
|
tr := NewTree()
|
||||||
tr.AddRouter("/shop/:id/account", "astaxie")
|
tr.AddRouter("/shop/:id/account", "astaxie")
|
||||||
|
Loading…
Reference in New Issue
Block a user