fix issue #3430: reverse sequence of generating leaves of router prefix tree
This commit is contained in:
parent
49d763dc6c
commit
a3d652974b
@ -210,9 +210,9 @@ func (t *Tree) AddRouter(pattern string, runObject interface{}) {
|
|||||||
func (t *Tree) addseg(segments []string, route interface{}, wildcards []string, reg string) {
|
func (t *Tree) addseg(segments []string, route interface{}, wildcards []string, reg string) {
|
||||||
if len(segments) == 0 {
|
if len(segments) == 0 {
|
||||||
if reg != "" {
|
if reg != "" {
|
||||||
t.leaves = append(t.leaves, &leafInfo{runObject: route, wildcards: wildcards, regexps: regexp.MustCompile("^" + reg + "$")})
|
t.leaves = append([]*leafInfo{{runObject: route, wildcards: wildcards, regexps: regexp.MustCompile("^" + reg + "$")}}, t.leaves...)
|
||||||
} else {
|
} else {
|
||||||
t.leaves = append(t.leaves, &leafInfo{runObject: route, wildcards: wildcards})
|
t.leaves = append([]*leafInfo{{runObject: route, wildcards: wildcards}}, t.leaves...)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
seg := segments[0]
|
seg := segments[0]
|
||||||
|
|||||||
@ -74,6 +74,17 @@ func init() {
|
|||||||
routers = append(routers, testinfo{"/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", "/v1/2_cms/ttt_123_1.html", map[string]string{":v": "2", ":id": "123", ":page": "1"}})
|
routers = append(routers, testinfo{"/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", "/v1/2_cms/ttt_123_1.html", map[string]string{":v": "2", ":id": "123", ":page": "1"}})
|
||||||
routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members", map[string]string{":pid": "1"}})
|
routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members", map[string]string{":pid": "1"}})
|
||||||
routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members/2", map[string]string{":pid": "1", ":mid": "2"}})
|
routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members/2", map[string]string{":pid": "1", ":mid": "2"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/?:month/?:day", "/2020/11/10", map[string]string{":year": "2020", ":month": "11", ":day": "10"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/?:month/?:day", "/2020/11", map[string]string{":year": "2020", ":month": "11"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year", "/2020", map[string]string{":year": "2020"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year([0-9]+)/?:month([0-9]+)/mid/?:day([0-9]+)/?:hour([0-9]+)", "/2020/11/mid/10/24", map[string]string{":year": "2020", ":month": "11", ":day": "10", ":hour": "24"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/?:month/mid/?:day/?:hour", "/2020/mid/10", map[string]string{":year": "2020", ":day": "10"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/?:month/mid/?:day/?:hour", "/2020/11/mid", map[string]string{":year": "2020", ":month": "11"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/?:month/mid/?:day/?:hour", "/mid/10/24", map[string]string{":day": "10", ":hour": "24"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year([0-9]+)/:month([0-9]+)/mid/:day([0-9]+)/?:hour([0-9]+)", "/2020/11/mid/10/24", map[string]string{":year": "2020", ":month": "11", ":day": "10", ":hour": "24"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/:month/mid/:day/?:hour", "/11/mid/10/24", map[string]string{":month": "11", ":day": "10"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/:month/mid/:day/?:hour", "/2020/11/mid/10", map[string]string{":year": "2020", ":month": "11", ":day": "10"}})
|
||||||
|
routers = append(routers, testinfo{"/?:year/:month/mid/:day/?:hour", "/11/mid/10", map[string]string{":month": "11", ":day": "10"}})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTreeRouters(t *testing.T) {
|
func TestTreeRouters(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user