4f4f7ce2 by astaxie

beego: fix the router for *.* with other regexp

1 parent 0692f928
...@@ -237,13 +237,19 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string, ...@@ -237,13 +237,19 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
237 regexpStr = "/" + regexpStr 237 regexpStr = "/" + regexpStr
238 } 238 }
239 } else if reg != "" { 239 } else if reg != "" {
240 if seg == "*.*" {
241 regexpStr = "/([^.]+).(.+)"
242 } else {
240 for _, w := range params { 243 for _, w := range params {
244
241 if w == "." || w == ":" { 245 if w == "." || w == ":" {
242 continue 246 continue
243 } 247 }
244 regexpStr = "/([^/]+)" + regexpStr 248 regexpStr = "/([^/]+)" + regexpStr
245 } 249 }
246 } 250 }
251
252 }
247 t.wildcard.addseg(segments[1:], route, append(wildcards, params...), reg+regexpStr) 253 t.wildcard.addseg(segments[1:], route, append(wildcards, params...), reg+regexpStr)
248 } else { 254 } else {
249 subTree, ok := t.fixrouters[seg] 255 subTree, ok := t.fixrouters[seg]
...@@ -396,6 +402,7 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string ...@@ -396,6 +402,7 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string
396 } 402 }
397 return true, params 403 return true, params
398 } 404 }
405
399 if !leaf.regexps.MatchString(path.Join(wildcardValues...)) { 406 if !leaf.regexps.MatchString(path.Join(wildcardValues...)) {
400 return false, nil 407 return false, nil
401 } 408 }
......
...@@ -42,6 +42,9 @@ func init() { ...@@ -42,6 +42,9 @@ func init() {
42 routers = append(routers, testinfo{"/*.*", "/nice/api.json", map[string]string{":path": "nice/api", ":ext": "json"}}) 42 routers = append(routers, testinfo{"/*.*", "/nice/api.json", map[string]string{":path": "nice/api", ":ext": "json"}})
43 routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) 43 routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}})
44 routers = append(routers, testinfo{"/:name/test/*.*", "/nice/test/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) 44 routers = append(routers, testinfo{"/:name/test/*.*", "/nice/test/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}})
45 routers = append(routers, testinfo{"/dl/:width:int/:height:int/*.*",
46 "/dl/48/48/05ac66d9bda00a3acf948c43e306fc9a.jpg",
47 map[string]string{":width": "48", ":height": "48", ":ext": "jpg", ":path": "05ac66d9bda00a3acf948c43e306fc9a"}})
45 routers = append(routers, testinfo{"/v1/shop/:id:int", "/v1/shop/123", map[string]string{":id": "123"}}) 48 routers = append(routers, testinfo{"/v1/shop/:id:int", "/v1/shop/123", map[string]string{":id": "123"}})
46 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"}}) 49 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"}})
47 routers = append(routers, testinfo{"/v1/shop/:id/:name", "/v1/shop/123/nike", map[string]string{":id": "123", ":name": "nike"}}) 50 routers = append(routers, testinfo{"/v1/shop/:id/:name", "/v1/shop/123/nike", map[string]string{":id": "123", ":name": "nike"}})
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!