085c362f by astaxie

beego:fix router expge

1 parent c3a07555
...@@ -428,7 +428,9 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin ...@@ -428,7 +428,9 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
428 if c.routerType == routerTypeBeego && c.controllerType.Name() == controllName { 428 if c.routerType == routerTypeBeego && c.controllerType.Name() == controllName {
429 find := false 429 find := false
430 if _, ok := HTTPMETHOD[strings.ToUpper(methodName)]; ok { 430 if _, ok := HTTPMETHOD[strings.ToUpper(methodName)]; ok {
431 if m, ok := c.methods[strings.ToUpper(methodName)]; ok && m == strings.ToUpper(methodName) { 431 if len(c.methods) == 0 {
432 find = true
433 } else if m, ok := c.methods[strings.ToUpper(methodName)]; ok && m == strings.ToUpper(methodName) {
432 find = true 434 find = true
433 } else if m, ok = c.methods["*"]; ok && m == methodName { 435 } else if m, ok = c.methods["*"]; ok && m == methodName {
434 find = true 436 find = true
...@@ -504,6 +506,9 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin ...@@ -504,6 +506,9 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
504 } 506 }
505 } 507 }
506 if l.regexps.MatchString(regurl) { 508 if l.regexps.MatchString(regurl) {
509 if url == "/" {
510 return true, url + regurl + tourl(params)
511 } else {
507 return true, url + "/" + regurl + tourl(params) 512 return true, url + "/" + regurl + tourl(params)
508 } 513 }
509 } 514 }
...@@ -511,6 +516,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin ...@@ -511,6 +516,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
511 } 516 }
512 } 517 }
513 } 518 }
519 }
514 520
515 return false, "" 521 return false, ""
516 } 522 }
......
...@@ -99,6 +99,7 @@ func TestUrlFor2(t *testing.T) { ...@@ -99,6 +99,7 @@ func TestUrlFor2(t *testing.T) {
99 handler := NewControllerRegister() 99 handler := NewControllerRegister()
100 handler.Add("/v1/:v/cms_:id(.+)_:page(.+).html", &TestController{}, "*:List") 100 handler.Add("/v1/:v/cms_:id(.+)_:page(.+).html", &TestController{}, "*:List")
101 handler.Add("/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", &TestController{}, "*:Param") 101 handler.Add("/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", &TestController{}, "*:Param")
102 handler.Add("/:year:int/:month:int/:title/:entid", &TestController{})
102 if handler.UrlFor("TestController.List", ":v", "za", ":id", "12", ":page", "123") != 103 if handler.UrlFor("TestController.List", ":v", "za", ":id", "12", ":page", "123") !=
103 "/v1/za/cms_12_123.html" { 104 "/v1/za/cms_12_123.html" {
104 Info(handler.UrlFor("TestController.List")) 105 Info(handler.UrlFor("TestController.List"))
...@@ -109,6 +110,12 @@ func TestUrlFor2(t *testing.T) { ...@@ -109,6 +110,12 @@ func TestUrlFor2(t *testing.T) {
109 Info(handler.UrlFor("TestController.Param")) 110 Info(handler.UrlFor("TestController.Param"))
110 t.Errorf("TestController.List must equal to /v1/za_cms/ttt_12_123.html") 111 t.Errorf("TestController.List must equal to /v1/za_cms/ttt_12_123.html")
111 } 112 }
113 if handler.UrlFor("TestController.Get", ":year", "1111", ":month", "11",
114 ":title", "aaaa", ":entid", "aaaa") !=
115 "/1111/11/aaaa/aaaa" {
116 Info(handler.UrlFor("TestController.Get"))
117 t.Errorf("TestController.Get must equal to /1111/11/aaaa/aaaa")
118 }
112 } 119 }
113 120
114 func TestUserFunc(t *testing.T) { 121 func TestUserFunc(t *testing.T) {
......
...@@ -160,6 +160,13 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string, ...@@ -160,6 +160,13 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
160 } else { 160 } else {
161 regexpStr = "/" + regexpStr 161 regexpStr = "/" + regexpStr
162 } 162 }
163 } else if reg != "" {
164 for _, w := range params {
165 if w == "." || w == ":" {
166 continue
167 }
168 regexpStr = "/([^/]+)" + regexpStr
169 }
163 } 170 }
164 t.wildcard.addseg(segments[1:], route, append(wildcards, params...), reg+regexpStr) 171 t.wildcard.addseg(segments[1:], route, append(wildcards, params...), reg+regexpStr)
165 } else { 172 } else {
......
...@@ -24,6 +24,7 @@ func init() { ...@@ -24,6 +24,7 @@ func init() {
24 routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) 24 routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}})
25 routers = append(routers, testinfo{"/:name/test/*.*", "/nice/test/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) 25 routers = append(routers, testinfo{"/:name/test/*.*", "/nice/test/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}})
26 routers = append(routers, testinfo{"/v1/shop/:id:int", "/v1/shop/123", map[string]string{":id": "123"}}) 26 routers = append(routers, testinfo{"/v1/shop/:id:int", "/v1/shop/123", map[string]string{":id": "123"}})
27 routers = append(routers, testinfo{"/:year:int/:month:int/:id/:endid", "/1111/111/aaa/aaa", map[string]string{":year": "1111", ":month": "111", ":id": "aaa", ":endid": "aaa"}})
27 routers = append(routers, testinfo{"/v1/shop/:id/:name", "/v1/shop/123/nike", map[string]string{":id": "123", ":name": "nike"}}) 28 routers = append(routers, testinfo{"/v1/shop/:id/:name", "/v1/shop/123/nike", map[string]string{":id": "123", ":name": "nike"}})
28 routers = append(routers, testinfo{"/v1/shop/:id/account", "/v1/shop/123/account", map[string]string{":id": "123"}}) 29 routers = append(routers, testinfo{"/v1/shop/:id/account", "/v1/shop/123/account", map[string]string{":id": "123"}})
29 routers = append(routers, testinfo{"/v1/shop/:name:string", "/v1/shop/nike", map[string]string{":name": "nike"}}) 30 routers = append(routers, testinfo{"/v1/shop/:name:string", "/v1/shop/nike", map[string]string{":name": "nike"}})
......
...@@ -248,7 +248,7 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha { ...@@ -248,7 +248,7 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
248 cpt := NewCaptcha(urlPrefix, store) 248 cpt := NewCaptcha(urlPrefix, store)
249 249
250 // create filter for serve captcha image 250 // create filter for serve captcha image
251 beego.AddFilter(cpt.URLPrefix+":", "BeforeRouter", cpt.Handler) 251 beego.InsertFilter(cpt.URLPrefix+":", beego.BeforeRouter, cpt.Handler)
252 252
253 // add to template func map 253 // add to template func map
254 beego.AddFuncMap("create_captcha", cpt.CreateCaptchaHtml) 254 beego.AddFuncMap("create_captcha", cpt.CreateCaptchaHtml)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!