Skip to content

Commit 5793765

Browse files
asahasrabuddhevishr
andcommitted
Fix param value bug (#1467)
* set parameter value in the pvalues slice * update echo version * update travis yml to fix failing build and add go modules support * Add tests * Update router_test.go Co-authored-by: Vishal Rana <vr@labstack.com>
1 parent 07ec791 commit 5793765

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ go:
33
- 1.12.x
44
- 1.13.x
55
- tip
6+
env:
7+
- GO111MODULE=on
68
install:
79
- go get -v golang.org/x/lint/golint
810
script:

echo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ const (
227227

228228
const (
229229
// Version of Echo
230-
Version = "4.1.11"
230+
Version = "4.1.13"
231231
website = "https://echo.labstack.com"
232232
// http://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=Echo
233233
banner = `

router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ func (r *Router) Find(method, path string, c Context) {
412412
// Consider param route one level up only
413413
// if no slash is remaining in search string
414414
if cn = nn.findChildByKind(pkind); cn != nil && strings.IndexByte(ns, '/') == -1 {
415+
pvalues[len(cn.pnames)-1] = search
415416
break
416417
}
417418
for {

router_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,42 @@ func TestRouterMixedParams(t *testing.T) {
11181118
testRouterAPI(t, api2)
11191119
}
11201120

1121+
// Issue #1466
1122+
func TestRouterParam1466(t *testing.T) {
1123+
e := New()
1124+
r := e.router
1125+
1126+
r.Add(http.MethodPost, "/users/signup", func(c Context) error {
1127+
return nil
1128+
})
1129+
r.Add(http.MethodPost, "/users/signup/bulk", func(c Context) error {
1130+
return nil
1131+
})
1132+
r.Add(http.MethodPost, "/users/survey", func(c Context) error {
1133+
return nil
1134+
})
1135+
r.Add(http.MethodGet, "/users/:username", func(c Context) error {
1136+
return nil
1137+
})
1138+
r.Add(http.MethodGet, "/interests/:name/users", func(c Context) error {
1139+
return nil
1140+
})
1141+
r.Add(http.MethodGet, "/skills/:name/users", func(c Context) error {
1142+
return nil
1143+
})
1144+
1145+
c := e.NewContext(nil, nil).(*context)
1146+
1147+
r.Find(http.MethodGet, "/users/ajitem", c)
1148+
assert.Equal(t, "ajitem", c.Param("username"))
1149+
1150+
r.Find(http.MethodGet, "/users/sharewithme", c)
1151+
assert.Equal(t, "sharewithme", c.Param("username"))
1152+
1153+
r.Find(http.MethodGet, "/users/signup", c)
1154+
assert.Equal(t, "", c.Param("username"))
1155+
}
1156+
11211157
func benchmarkRouterRoutes(b *testing.B, routes []*Route) {
11221158
e := New()
11231159
r := e.router

0 commit comments

Comments
 (0)