1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:00:54 +00:00

update route variables should not have underline

This commit is contained in:
maxin 2016-07-30 21:57:23 +08:00
parent 5d1e60b468
commit b89bfe76d0
2 changed files with 6 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/Maxgis/tree"
"github.com/astaxie/beego/context" "github.com/astaxie/beego/context"
"github.com/astaxie/beego/utils" "github.com/astaxie/beego/utils"
) )
@ -467,7 +468,7 @@ func splitPath(key string) []string {
// ":name:string" -> true, [:name], ([\w]+) // ":name:string" -> true, [:name], ([\w]+)
// ":id([0-9]+)" -> true, [:id], ([0-9]+) // ":id([0-9]+)" -> true, [:id], ([0-9]+)
// ":id([0-9]+)_:name" -> true, [:id :name], ([0-9]+)_(.+) // ":id([0-9]+)_:name" -> true, [:id :name], ([0-9]+)_(.+)
// "cms_:id_:page.html" -> true, [:id_ :page], cms_(.+)(.+).html // "cms_:id_:page.html" -> true, [:id :page], cms_(.+)_(.+).html
// "cms_:id(.+)_:page.html" -> true, [:id :page], cms_(.+)_(.+).html // "cms_:id(.+)_:page.html" -> true, [:id :page], cms_(.+)_(.+).html
// "*" -> true, [:splat], "" // "*" -> true, [:splat], ""
// "*.*" -> true,[. :path :ext], "" . meaning separator // "*.*" -> true,[. :path :ext], "" . meaning separator
@ -487,7 +488,7 @@ func splitSegment(key string) (bool, []string, string) {
var expt []rune var expt []rune
var skipnum int var skipnum int
params := []string{} params := []string{}
reg := regexp.MustCompile(`[a-zA-Z0-9_]+`) reg := regexp.MustCompile(`[a-zA-Z0-9]+`)
for i, v := range key { for i, v := range key {
if skipnum > 0 { if skipnum > 0 {
skipnum-- skipnum--
@ -574,6 +575,7 @@ func splitSegment(key string) (bool, []string, string) {
} }
params = append(params, ":"+string(param)) params = append(params, ":"+string(param))
} }
tree.Print(string(out))
return true, params, string(out) return true, params, string(out)
} }
return false, nil, "" return false, nil, ""

View File

@ -74,6 +74,8 @@ 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{"/page/:id_:page", "/page/12_33", map[string]string{":id": "12", ":page": "33"}})
routers = append(routers, testinfo{"/page/:id_:page.html", "/page/12_33.html", map[string]string{":id": "12", ":page": "33"}})
} }
func TestTreeRouters(t *testing.T) { func TestTreeRouters(t *testing.T) {