mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 10:10:54 +00:00
commit
5973ef107c
@ -89,7 +89,7 @@ func (input *BeegoInput) URI() string {
|
|||||||
|
|
||||||
// URL returns the request url path (without query, string and fragment).
|
// URL returns the request url path (without query, string and fragment).
|
||||||
func (input *BeegoInput) URL() string {
|
func (input *BeegoInput) URL() string {
|
||||||
return input.Context.Request.URL.EscapedPath()
|
return input.Context.Request.URL.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
// Site returns the base site url as scheme://domain type.
|
// Site returns the base site url as scheme://domain type.
|
||||||
|
@ -212,6 +212,23 @@ func TestAutoExtFunc(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEscape(t *testing.T) {
|
||||||
|
|
||||||
|
r, _ := http.NewRequest("GET", "/search/%E4%BD%A0%E5%A5%BD", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handler := NewControllerRegister()
|
||||||
|
handler.Get("/search/:keyword(.+)", func(ctx *context.Context) {
|
||||||
|
value := ctx.Input.Param(":keyword")
|
||||||
|
ctx.Output.Body([]byte(value))
|
||||||
|
})
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
str := w.Body.String()
|
||||||
|
if str != "你好" {
|
||||||
|
t.Errorf("incorrect, %s", str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRouteOk(t *testing.T) {
|
func TestRouteOk(t *testing.T) {
|
||||||
|
|
||||||
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
|
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
|
||||||
|
@ -33,13 +33,13 @@ var (
|
|||||||
// wildcard stores params
|
// wildcard stores params
|
||||||
// leaves store the endpoint information
|
// leaves store the endpoint information
|
||||||
type Tree struct {
|
type Tree struct {
|
||||||
//prefix set for static router
|
// prefix set for static router
|
||||||
prefix string
|
prefix string
|
||||||
//search fix route first
|
// search fix route first
|
||||||
fixrouters []*Tree
|
fixrouters []*Tree
|
||||||
//if set, failure to match fixrouters search then search wildcard
|
// if set, failure to match fixrouters search then search wildcard
|
||||||
wildcard *Tree
|
wildcard *Tree
|
||||||
//if set, failure to match wildcard search
|
// if set, failure to match wildcard search
|
||||||
leaves []*leafInfo
|
leaves []*leafInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,13 +69,13 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st
|
|||||||
filterTreeWithPrefix(tree, wildcards, reg)
|
filterTreeWithPrefix(tree, wildcards, reg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Rule: /login/*/access match /login/2009/11/access
|
// Rule: /login/*/access match /login/2009/11/access
|
||||||
//if already has *, and when loop the access, should as a regexpStr
|
// if already has *, and when loop the access, should as a regexpStr
|
||||||
if !iswild && utils.InSlice(":splat", wildcards) {
|
if !iswild && utils.InSlice(":splat", wildcards) {
|
||||||
iswild = true
|
iswild = true
|
||||||
regexpStr = seg
|
regexpStr = seg
|
||||||
}
|
}
|
||||||
//Rule: /user/:id/*
|
// Rule: /user/:id/*
|
||||||
if seg == "*" && len(wildcards) > 0 && reg == "" {
|
if seg == "*" && len(wildcards) > 0 && reg == "" {
|
||||||
regexpStr = "(.+)"
|
regexpStr = "(.+)"
|
||||||
}
|
}
|
||||||
@ -222,13 +222,13 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
|
|||||||
t.addseg(segments[1:], route, wildcards, reg)
|
t.addseg(segments[1:], route, wildcards, reg)
|
||||||
params = params[1:]
|
params = params[1:]
|
||||||
}
|
}
|
||||||
//Rule: /login/*/access match /login/2009/11/access
|
// Rule: /login/*/access match /login/2009/11/access
|
||||||
//if already has *, and when loop the access, should as a regexpStr
|
// if already has *, and when loop the access, should as a regexpStr
|
||||||
if !iswild && utils.InSlice(":splat", wildcards) {
|
if !iswild && utils.InSlice(":splat", wildcards) {
|
||||||
iswild = true
|
iswild = true
|
||||||
regexpStr = seg
|
regexpStr = seg
|
||||||
}
|
}
|
||||||
//Rule: /user/:id/*
|
// Rule: /user/:id/*
|
||||||
if seg == "*" && len(wildcards) > 0 && reg == "" {
|
if seg == "*" && len(wildcards) > 0 && reg == "" {
|
||||||
regexpStr = "(.+)"
|
regexpStr = "(.+)"
|
||||||
}
|
}
|
||||||
@ -393,7 +393,7 @@ type leafInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (leaf *leafInfo) match(treePattern string, wildcardValues []string, ctx *context.Context) (ok bool) {
|
func (leaf *leafInfo) match(treePattern string, wildcardValues []string, ctx *context.Context) (ok bool) {
|
||||||
//fmt.Println("Leaf:", wildcardValues, leaf.wildcards, leaf.regexps)
|
// fmt.Println("Leaf:", wildcardValues, leaf.wildcards, leaf.regexps)
|
||||||
if leaf.regexps == nil {
|
if leaf.regexps == nil {
|
||||||
if len(wildcardValues) == 0 && len(leaf.wildcards) == 0 { // static path
|
if len(wildcardValues) == 0 && len(leaf.wildcards) == 0 { // static path
|
||||||
return true
|
return true
|
||||||
@ -500,7 +500,7 @@ func splitSegment(key string) (bool, []string, string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if start {
|
if start {
|
||||||
//:id:int and :name:string
|
// :id:int and :name:string
|
||||||
if v == ':' {
|
if v == ':' {
|
||||||
if len(key) >= i+4 {
|
if len(key) >= i+4 {
|
||||||
if key[i+1:i+4] == "int" {
|
if key[i+1:i+4] == "int" {
|
||||||
|
Loading…
Reference in New Issue
Block a user