Description
If I have two routes defined, one with a static value and one with a path param, the static value cannot be used as the path param even if the two routes do not have the same number of path segments.
For example, if I define these two routes:
GET /users/:id/comments // 3 path segments
GET /:resourceName/:id // 2 path segments
The second route fails when :resourceId is users (but works for any other value). I'm confused by this behavior. I know the matching order is static -> param -> any, but I would have thought that if no match was found down the static /users path, the router would then attempt to match down the /:resourceId path.
Checklist
Expected behaviour
All of these requests should work:
GET /users/1/comments
GET /boozers/1
GET /users/1
Actual behaviour
These two work:
GET /users/1/comments
GET /boozers/1
But this fails:
Steps to reproduce
Working code to debug
package main
import (
"testing"
"github.com/labstack/echo"
"github.com/stretchr/testify/assert"
)
func TestRouteConflict(t *testing.T) {
e := echo.New()
r := e.Router()
e.GET("/users/:id/comments", func(c echo.Context) error {
c.Set("r", 1)
return nil
})
e.GET("/:resourceName/:id", func(c echo.Context) error {
c.Set("r", 2)
return nil
})
c := e.NewContext(nil, nil)
r.Find(echo.GET, "/users/1/comments", c)
c.Handler()(c)
assert.Equal(t, 1, c.Get("r"))
c = e.NewContext(nil, nil)
r.Find(echo.GET, "/boozers/1", c)
c.Handler()(c)
assert.Equal(t, 2, c.Get("r"))
c = e.NewContext(nil, nil)
r.Find(echo.GET, "/users/1", c)
c.Handler()(c)
assert.Equal(t, 2, c.Get("r")) // this assertion fails
}
Version/commit
3.1.0-rc1
Description
If I have two routes defined, one with a static value and one with a path param, the static value cannot be used as the path param even if the two routes do not have the same number of path segments.
For example, if I define these two routes:
The second route fails when
:resourceIdisusers(but works for any other value). I'm confused by this behavior. I know the matching order is static -> param -> any, but I would have thought that if no match was found down the static/userspath, the router would then attempt to match down the/:resourceIdpath.Checklist
Expected behaviour
All of these requests should work:
Actual behaviour
These two work:
But this fails:
Steps to reproduce
Working code to debug
Version/commit
3.1.0-rc1