Skip to content

Commit d5f968d

Browse files
committed
Merge pull request revel#886 from revel/bug/reverse-route-wildcard
Fixes wildcard reverse routing logic and adds test
2 parents 74cf8cc + fa99767 commit d5f968d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (router *Router) Reverse(action string, argValues map[string]string) *Actio
375375
pathElements = strings.Split(route.Path, "/")
376376
)
377377
for i, el := range pathElements {
378-
if el == "" || el[0] != ':' {
378+
if el == "" || (el[0] != ':' && el[0] != '*') {
379379
continue
380380
}
381381

router_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ var routeTestCases = map[string]*Route{
3232
FixedParams: []string{},
3333
},
3434

35-
`get /apps/:appId/ Application.Show`: &Route{
35+
`get /app/:appId/ Application.Show`: &Route{
3636
Method: "GET",
37-
Path: `/apps/:appId/`,
37+
Path: `/app/:appId/`,
3838
Action: "Application.Show",
3939
FixedParams: []string{},
4040
},
4141

42+
`get /app-wild/*appId/ Application.WildShow`: &Route{
43+
Method: "GET",
44+
Path: `/app-wild/*appId/`,
45+
Action: "Application.WildShow",
46+
FixedParams: []string{},
47+
},
48+
4249
`GET /public/:filepath Static.Serve("public")`: &Route{
4350
Method: "GET",
4451
Path: "/public/:filepath",
@@ -107,6 +114,7 @@ const TEST_ROUTES = `
107114
GET / Application.Index
108115
GET /test/ Application.Index("Test", "Test2")
109116
GET /app/:id/ Application.Show
117+
GET /app-wild/*id/ Application.WildShow
110118
POST /app/:id Application.Save
111119
PATCH /app/:id/ Application.Update
112120
GET /javascript/:filepath Static.Serve("public/js")
@@ -316,6 +324,16 @@ var reverseRoutingTestCases = map[*ReverseRouteArgs]*ActionDefinition{
316324
Star: false,
317325
Action: "Application.Save",
318326
},
327+
328+
&ReverseRouteArgs{
329+
action: "Application.WildShow",
330+
args: map[string]string{"id": "123"},
331+
}: &ActionDefinition{
332+
Url: "/app-wild/123/",
333+
Method: "GET",
334+
Star: false,
335+
Action: "Application.WildShow",
336+
},
319337
}
320338

321339
func TestReverseRouting(t *testing.T) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy