1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

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>
This commit is contained in:
Ajitem Sahasrabuddhe 2020-01-01 22:27:00 +05:30 committed by Vishal Rana
parent 07ec791103
commit 5793765eed
4 changed files with 40 additions and 1 deletions

View File

@ -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:

View File

@ -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 = `

View File

@ -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 {

View File

@ -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