2f8a70d5 by astaxie

beego: router support param has _

1 parent 7c0d0900
...@@ -284,7 +284,7 @@ func splitSegment(key string) (bool, []string, string) { ...@@ -284,7 +284,7 @@ func splitSegment(key string) (bool, []string, string) {
284 var expt []rune 284 var expt []rune
285 var skipnum int 285 var skipnum int
286 params := []string{} 286 params := []string{}
287 reg := regexp.MustCompile(`[a-zA-Z0-9]+`) 287 reg := regexp.MustCompile(`[a-zA-Z0-9_]+`)
288 for i, v := range key { 288 for i, v := range key {
289 if skipnum > 0 { 289 if skipnum > 0 {
290 skipnum -= 1 290 skipnum -= 1
......
...@@ -29,8 +29,8 @@ func init() { ...@@ -29,8 +29,8 @@ func init() {
29 routers = append(routers, testinfo{"/v1/shop/:name:string", "/v1/shop/nike", map[string]string{":name": "nike"}}) 29 routers = append(routers, testinfo{"/v1/shop/:name:string", "/v1/shop/nike", map[string]string{":name": "nike"}})
30 routers = append(routers, testinfo{"/v1/shop/:id([0-9]+)", "/v1/shop//123", map[string]string{":id": "123"}}) 30 routers = append(routers, testinfo{"/v1/shop/:id([0-9]+)", "/v1/shop//123", map[string]string{":id": "123"}})
31 routers = append(routers, testinfo{"/v1/shop/:id([0-9]+)_:name", "/v1/shop/123_nike", map[string]string{":id": "123", ":name": "nike"}}) 31 routers = append(routers, testinfo{"/v1/shop/:id([0-9]+)_:name", "/v1/shop/123_nike", map[string]string{":id": "123", ":name": "nike"}})
32 routers = append(routers, testinfo{"/v1/shop/:id_cms.html", "/v1/shop/123_cms.html", map[string]string{":id": "123"}}) 32 routers = append(routers, testinfo{"/v1/shop/:id(.+)_cms.html", "/v1/shop/123_cms.html", map[string]string{":id": "123"}})
33 routers = append(routers, testinfo{"/v1/shop/cms_:id_:page.html", "/v1/shop/cms_123_1.html", map[string]string{":id": "123", ":page": "1"}}) 33 routers = append(routers, testinfo{"/v1/shop/cms_:id(.+)_:page(.+).html", "/v1/shop/cms_123_1.html", map[string]string{":id": "123", ":page": "1"}})
34 } 34 }
35 35
36 func TestTreeRouters(t *testing.T) { 36 func TestTreeRouters(t *testing.T) {
...@@ -113,11 +113,11 @@ func TestSplitSegment(t *testing.T) { ...@@ -113,11 +113,11 @@ func TestSplitSegment(t *testing.T) {
113 if !b || len(w) != 2 || w[0] != ":id" || w[1] != ":name" || r != `([0-9]+)_(.+)` { 113 if !b || len(w) != 2 || w[0] != ":id" || w[1] != ":name" || r != `([0-9]+)_(.+)` {
114 t.Fatal(`:id([0-9]+)_:name should return true, [:id :name], '([0-9]+)_(.+)'`) 114 t.Fatal(`:id([0-9]+)_:name should return true, [:id :name], '([0-9]+)_(.+)'`)
115 } 115 }
116 b, w, r = splitSegment(":id_cms.html") 116 b, w, r = splitSegment(":id(.+)_cms.html")
117 if !b || len(w) != 1 || w[0] != ":id" || r != `(.+)_cms.html` { 117 if !b || len(w) != 1 || w[0] != ":id" || r != `(.+)_cms.html` {
118 t.Fatal(":id_cms.html should return true, [:id], '(.+)_cms.html'") 118 t.Fatal(":id_cms.html should return true, [:id], '(.+)_cms.html'")
119 } 119 }
120 b, w, r = splitSegment("cms_:id_:page.html") 120 b, w, r = splitSegment("cms_:id(.+)_:page(.+).html")
121 if !b || len(w) != 2 || w[0] != ":id" || w[1] != ":page" || r != `cms_(.+)_(.+).html` { 121 if !b || len(w) != 2 || w[0] != ":id" || w[1] != ":page" || r != `cms_(.+)_(.+).html` {
122 t.Fatal(":id_cms.html should return true, [:id :page], cms_(.+)_(.+).html") 122 t.Fatal(":id_cms.html should return true, [:id :page], cms_(.+)_(.+).html")
123 } 123 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!