Skip to content

Commit

Permalink
Fix param value bug (#1467)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
asahasrabuddhe and vishr committed Jan 1, 2020
1 parent 07ec791 commit 5793765
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ go:
- 1.12.x
- 1.13.x
- tip
env:
- GO111MODULE=on
install:
- go get -v golang.org/x/lint/golint
script:
Expand Down
2 changes: 1 addition & 1 deletion echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const (

const (
// Version of Echo
Version = "4.1.11"
Version = "4.1.13"
website = "https://echo.labstack.com"
// http://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=Echo
banner = `
Expand Down
1 change: 1 addition & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func (r *Router) Find(method, path string, c Context) {
// Consider param route one level up only
// if no slash is remaining in search string
if cn = nn.findChildByKind(pkind); cn != nil && strings.IndexByte(ns, '/') == -1 {
pvalues[len(cn.pnames)-1] = search
break
}
for {
Expand Down
36 changes: 36 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,42 @@ func TestRouterMixedParams(t *testing.T) {
testRouterAPI(t, api2)
}

// Issue #1466
func TestRouterParam1466(t *testing.T) {
e := New()
r := e.router

r.Add(http.MethodPost, "/users/signup", func(c Context) error {
return nil
})
r.Add(http.MethodPost, "/users/signup/bulk", func(c Context) error {
return nil
})
r.Add(http.MethodPost, "/users/survey", func(c Context) error {
return nil
})
r.Add(http.MethodGet, "/users/:username", func(c Context) error {
return nil
})
r.Add(http.MethodGet, "/interests/:name/users", func(c Context) error {
return nil
})
r.Add(http.MethodGet, "/skills/:name/users", func(c Context) error {
return nil
})

c := e.NewContext(nil, nil).(*context)

r.Find(http.MethodGet, "/users/ajitem", c)
assert.Equal(t, "ajitem", c.Param("username"))

r.Find(http.MethodGet, "/users/sharewithme", c)
assert.Equal(t, "sharewithme", c.Param("username"))

r.Find(http.MethodGet, "/users/signup", c)
assert.Equal(t, "", c.Param("username"))
}

func benchmarkRouterRoutes(b *testing.B, routes []*Route) {
e := New()
r := e.router
Expand Down

0 comments on commit 5793765

Please sign in to comment.