Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
085c362f
Commit
085c362f
authored
Jun 18, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego:fix router expge
parent
c3a07555
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
3 deletions
+24
-3
router.go
router.go
+8
-2
router_test.go
router_test.go
+7
-0
tree.go
tree.go
+7
-0
tree_test.go
tree_test.go
+1
-0
captcha.go
utils/captcha/captcha.go
+1
-1
No files found.
router.go
View file @
085c362f
...
...
@@ -428,7 +428,9 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
if
c
.
routerType
==
routerTypeBeego
&&
c
.
controllerType
.
Name
()
==
controllName
{
find
:=
false
if
_
,
ok
:=
HTTPMETHOD
[
strings
.
ToUpper
(
methodName
)];
ok
{
if
m
,
ok
:=
c
.
methods
[
strings
.
ToUpper
(
methodName
)];
ok
&&
m
==
strings
.
ToUpper
(
methodName
)
{
if
len
(
c
.
methods
)
==
0
{
find
=
true
}
else
if
m
,
ok
:=
c
.
methods
[
strings
.
ToUpper
(
methodName
)];
ok
&&
m
==
strings
.
ToUpper
(
methodName
)
{
find
=
true
}
else
if
m
,
ok
=
c
.
methods
[
"*"
];
ok
&&
m
==
methodName
{
find
=
true
...
...
@@ -504,7 +506,11 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
}
}
if
l
.
regexps
.
MatchString
(
regurl
)
{
return
true
,
url
+
"/"
+
regurl
+
tourl
(
params
)
if
url
==
"/"
{
return
true
,
url
+
regurl
+
tourl
(
params
)
}
else
{
return
true
,
url
+
"/"
+
regurl
+
tourl
(
params
)
}
}
}
}
...
...
router_test.go
View file @
085c362f
...
...
@@ -99,6 +99,7 @@ func TestUrlFor2(t *testing.T) {
handler
:=
NewControllerRegister
()
handler
.
Add
(
"/v1/:v/cms_:id(.+)_:page(.+).html"
,
&
TestController
{},
"*:List"
)
handler
.
Add
(
"/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html"
,
&
TestController
{},
"*:Param"
)
handler
.
Add
(
"/:year:int/:month:int/:title/:entid"
,
&
TestController
{})
if
handler
.
UrlFor
(
"TestController.List"
,
":v"
,
"za"
,
":id"
,
"12"
,
":page"
,
"123"
)
!=
"/v1/za/cms_12_123.html"
{
Info
(
handler
.
UrlFor
(
"TestController.List"
))
...
...
@@ -109,6 +110,12 @@ func TestUrlFor2(t *testing.T) {
Info
(
handler
.
UrlFor
(
"TestController.Param"
))
t
.
Errorf
(
"TestController.List must equal to /v1/za_cms/ttt_12_123.html"
)
}
if
handler
.
UrlFor
(
"TestController.Get"
,
":year"
,
"1111"
,
":month"
,
"11"
,
":title"
,
"aaaa"
,
":entid"
,
"aaaa"
)
!=
"/1111/11/aaaa/aaaa"
{
Info
(
handler
.
UrlFor
(
"TestController.Get"
))
t
.
Errorf
(
"TestController.Get must equal to /1111/11/aaaa/aaaa"
)
}
}
func
TestUserFunc
(
t
*
testing
.
T
)
{
...
...
tree.go
View file @
085c362f
...
...
@@ -160,6 +160,13 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
}
else
{
regexpStr
=
"/"
+
regexpStr
}
}
else
if
reg
!=
""
{
for
_
,
w
:=
range
params
{
if
w
==
"."
||
w
==
":"
{
continue
}
regexpStr
=
"/([^/]+)"
+
regexpStr
}
}
t
.
wildcard
.
addseg
(
segments
[
1
:
],
route
,
append
(
wildcards
,
params
...
),
reg
+
regexpStr
)
}
else
{
...
...
tree_test.go
View file @
085c362f
...
...
@@ -24,6 +24,7 @@ func init() {
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"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:id:int"
,
"/v1/shop/123"
,
map
[
string
]
string
{
":id"
:
"123"
}})
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"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:id/:name"
,
"/v1/shop/123/nike"
,
map
[
string
]
string
{
":id"
:
"123"
,
":name"
:
"nike"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:id/account"
,
"/v1/shop/123/account"
,
map
[
string
]
string
{
":id"
:
"123"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:name:string"
,
"/v1/shop/nike"
,
map
[
string
]
string
{
":name"
:
"nike"
}})
...
...
utils/captcha/captcha.go
View file @
085c362f
...
...
@@ -248,7 +248,7 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
cpt
:=
NewCaptcha
(
urlPrefix
,
store
)
// create filter for serve captcha image
beego
.
AddFilter
(
cpt
.
URLPrefix
+
":"
,
"BeforeRouter"
,
cpt
.
Handler
)
beego
.
InsertFilter
(
cpt
.
URLPrefix
+
":"
,
beego
.
BeforeRouter
,
cpt
.
Handler
)
// add to template func map
beego
.
AddFuncMap
(
"create_captcha"
,
cpt
.
CreateCaptchaHtml
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment