Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
b575fa1e
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b575fa1e
编写于
9月 11, 2020
作者:
M
Ming Deng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix 4219
上级
6bbca96c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
13 deletion
+30
-13
pkg/server/web/context/input.go
pkg/server/web/context/input.go
+1
-1
pkg/server/web/router_test.go
pkg/server/web/router_test.go
+17
-0
pkg/server/web/tree.go
pkg/server/web/tree.go
+12
-12
未找到文件。
pkg/server/web/context/input.go
浏览文件 @
b575fa1e
...
...
@@ -89,7 +89,7 @@ func (input *BeegoInput) URI() string {
// URL returns the request url path (without query, string and fragment).
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.
...
...
pkg/server/web/router_test.go
浏览文件 @
b575fa1e
...
...
@@ -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
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/anderson/thomas?learn=kungfu"
,
nil
)
...
...
pkg/server/web/tree.go
浏览文件 @
b575fa1e
...
...
@@ -33,13 +33,13 @@ var (
// wildcard stores params
// leaves store the endpoint information
type
Tree
struct
{
//prefix set for static router
//
prefix set for static router
prefix
string
//search fix route first
//
search fix route first
fixrouters
[]
*
Tree
//if set, failure to match fixrouters search then search wildcard
//
if set, failure to match fixrouters search then search wildcard
wildcard
*
Tree
//if set, failure to match wildcard search
//
if set, failure to match wildcard search
leaves
[]
*
leafInfo
}
...
...
@@ -69,13 +69,13 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st
filterTreeWithPrefix
(
tree
,
wildcards
,
reg
)
}
}
//Rule: /login/*/access match /login/2009/11/access
//if already has *, and when loop the access, should as a regexpStr
//
Rule: /login/*/access match /login/2009/11/access
//
if already has *, and when loop the access, should as a regexpStr
if
!
iswild
&&
utils
.
InSlice
(
":splat"
,
wildcards
)
{
iswild
=
true
regexpStr
=
seg
}
//Rule: /user/:id/*
//
Rule: /user/:id/*
if
seg
==
"*"
&&
len
(
wildcards
)
>
0
&&
reg
==
""
{
regexpStr
=
"(.+)"
}
...
...
@@ -222,13 +222,13 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
t
.
addseg
(
segments
[
1
:
],
route
,
wildcards
,
reg
)
params
=
params
[
1
:
]
}
//Rule: /login/*/access match /login/2009/11/access
//if already has *, and when loop the access, should as a regexpStr
//
Rule: /login/*/access match /login/2009/11/access
//
if already has *, and when loop the access, should as a regexpStr
if
!
iswild
&&
utils
.
InSlice
(
":splat"
,
wildcards
)
{
iswild
=
true
regexpStr
=
seg
}
//Rule: /user/:id/*
//
Rule: /user/:id/*
if
seg
==
"*"
&&
len
(
wildcards
)
>
0
&&
reg
==
""
{
regexpStr
=
"(.+)"
}
...
...
@@ -393,7 +393,7 @@ type leafInfo struct {
}
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
len
(
wildcardValues
)
==
0
&&
len
(
leaf
.
wildcards
)
==
0
{
// static path
return
true
...
...
@@ -500,7 +500,7 @@ func splitSegment(key string) (bool, []string, string) {
continue
}
if
start
{
//:id:int and :name:string
//
:id:int and :name:string
if
v
==
':'
{
if
len
(
key
)
>=
i
+
4
{
if
key
[
i
+
1
:
i
+
4
]
==
"int"
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录