Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a5a6a307
authored
2014-06-23 15:28:53 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
beego: fix the router rule for *
1 parent
1f6e689e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
13 deletions
router_test.go
tree.go
tree_test.go
router_test.go
View file @
a5a6a30
...
...
@@ -79,19 +79,23 @@ func TestUrlFor(t *testing.T) {
handler
:=
NewControllerRegister
()
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{},
"*:Param"
)
handler
.
AddAuto
(
&
TestController
{})
if
handler
.
UrlFor
(
"TestController.List"
)
!=
"/api/list"
{
Info
(
handler
.
UrlFor
(
"TestController.List"
))
if
a
:=
handler
.
UrlFor
(
"TestController.List"
);
a
!=
"/api/list"
{
Info
(
a
)
t
.
Errorf
(
"TestController.List must equal to /api/list"
)
}
if
handler
.
UrlFor
(
"TestController.Param"
,
":last"
,
"xie"
,
":first"
,
"asta"
)
!=
"/person/xie/asta"
{
t
.
Errorf
(
"TestController.Param must equal to /person/xie/asta, but get "
+
handler
.
UrlFor
(
"TestController.Param"
,
":last"
,
"xie"
,
":first"
,
"asta"
)
)
if
a
:=
handler
.
UrlFor
(
"TestController.Param"
,
":last"
,
"xie"
,
":first"
,
"asta"
);
a
!=
"/person/xie/asta"
{
t
.
Errorf
(
"TestController.Param must equal to /person/xie/asta, but get "
+
a
)
}
if
handler
.
UrlFor
(
"TestController.Myext"
)
!=
"/test/myext"
{
t
.
Errorf
(
"TestController.Myext must equal to /test/myext"
)
}
func
TestUrlFor3
(
t
*
testing
.
T
)
{
handler
:=
NewControllerRegister
()
handler
.
AddAuto
(
&
TestController
{})
if
a
:=
handler
.
UrlFor
(
"TestController.Myext"
);
a
!=
"/test/myext"
{
t
.
Errorf
(
"TestController.Myext must equal to /test/myext, but get "
+
a
)
}
if
handler
.
UrlFor
(
"TestController.GetUrl"
)
!=
"/test/geturl"
{
t
.
Errorf
(
"TestController.GetUrl must equal to /test/geturl
"
)
if
a
:=
handler
.
UrlFor
(
"TestController.GetUrl"
);
a
!=
"/test/geturl"
{
t
.
Errorf
(
"TestController.GetUrl must equal to /test/geturl
, but get "
+
a
)
}
}
...
...
tree.go
View file @
a5a6a30
...
...
@@ -137,26 +137,36 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
}
filterCards
=
append
(
filterCards
,
v
)
}
t
.
leaves
=
append
(
t
.
leaves
,
&
leafInfo
{
runObject
:
route
,
wildcards
:
wildc
ards
,
regexps
:
regexp
.
MustCompile
(
"^"
+
reg
+
"$"
)})
t
.
leaves
=
append
(
t
.
leaves
,
&
leafInfo
{
runObject
:
route
,
wildcards
:
filterC
ards
,
regexps
:
regexp
.
MustCompile
(
"^"
+
reg
+
"$"
)})
}
else
{
t
.
leaves
=
append
(
t
.
leaves
,
&
leafInfo
{
runObject
:
route
,
wildcards
:
wildcards
})
}
}
else
{
seg
:=
segments
[
0
]
iswild
,
params
,
regexpStr
:=
splitSegment
(
seg
)
//for the router /login/*/access match /login/2009/11/access
if
!
iswild
&&
utils
.
InSlice
(
":splat"
,
wildcards
)
{
iswild
=
true
regexpStr
=
seg
}
if
iswild
{
if
t
.
wildcard
==
nil
{
t
.
wildcard
=
NewTree
()
}
if
regexpStr
!=
""
{
if
reg
==
""
{
rr
:=
""
for
_
,
w
:=
range
wildcards
{
if
w
==
"."
||
w
==
":"
{
continue
}
regexpStr
=
"([^/]+)/"
+
regexpStr
if
w
==
":splat"
{
rr
=
rr
+
"(.+)/"
}
else
{
rr
=
rr
+
"([^/]+)/"
}
}
regexpStr
=
rr
+
regexpStr
}
else
{
regexpStr
=
"/"
+
regexpStr
}
...
...
tree_test.go
View file @
a5a6a30
...
...
@@ -19,6 +19,9 @@ func init() {
routers
=
append
(
routers
,
testinfo
{
"/customer/login"
,
"/customer/login.json"
,
map
[
string
]
string
{
":ext"
:
"json"
}})
routers
=
append
(
routers
,
testinfo
{
"/*"
,
"/customer/123"
,
map
[
string
]
string
{
":splat"
:
"customer/123"
}})
routers
=
append
(
routers
,
testinfo
{
"/*"
,
"/customer/2009/12/11"
,
map
[
string
]
string
{
":splat"
:
"customer/2009/12/11"
}})
routers
=
append
(
routers
,
testinfo
{
"/aa/*/bb"
,
"/aa/2009/bb"
,
map
[
string
]
string
{
":splat"
:
"2009"
}})
routers
=
append
(
routers
,
testinfo
{
"/cc/*/dd"
,
"/cc/2009/11/dd"
,
map
[
string
]
string
{
":splat"
:
"2009/11"
}})
routers
=
append
(
routers
,
testinfo
{
"/ee/:year/*/ff"
,
"/ee/2009/11/ff"
,
map
[
string
]
string
{
":year"
:
"2009"
,
":splat"
:
"11"
}})
routers
=
append
(
routers
,
testinfo
{
"/*.*"
,
"/nice/api.json"
,
map
[
string
]
string
{
":path"
:
"nice/api"
,
":ext"
:
"json"
}})
routers
=
append
(
routers
,
testinfo
{
"/:name/*.*"
,
"/nice/api.json"
,
map
[
string
]
string
{
":name"
:
"nice"
,
":path"
:
"api"
,
":ext"
:
"json"
}})
routers
=
append
(
routers
,
testinfo
{
"/:name/test/*.*"
,
"/nice/test/api.json"
,
map
[
string
]
string
{
":name"
:
"nice"
,
":path"
:
"api"
,
":ext"
:
"json"
}})
...
...
@@ -47,7 +50,7 @@ func TestTreeRouters(t *testing.T) {
if
r
.
params
!=
nil
{
for
k
,
v
:=
range
r
.
params
{
if
vv
,
ok
:=
param
[
k
];
!
ok
{
t
.
Fatal
(
r
.
url
+
r
.
requesturl
+
" get param empty:"
+
k
)
t
.
Fatal
(
r
.
url
+
" "
+
r
.
requesturl
+
" get param empty:"
+
k
)
}
else
if
vv
!=
v
{
t
.
Fatal
(
r
.
url
+
" "
+
r
.
requesturl
+
" should be:"
+
v
+
" get param:"
+
vv
)
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment