Skip to content

Commit

Permalink
Return an empty string for ctx.path if there is no registered path
Browse files Browse the repository at this point in the history
  • Loading branch information
brietaylor authored and aldas committed Jan 28, 2023
1 parent 24a3061 commit 08093a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 0 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ func optionsMethodHandler(allowMethods string) func(c Context) error {
// - Return it `Echo#ReleaseContext()`.
func (r *Router) Find(method, path string, c Context) {
ctx := c.(*context)
ctx.path = path
currentNode := r.tree // Current node as root

var (
Expand Down
12 changes: 12 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,18 @@ func TestRouterStatic(t *testing.T) {
assert.Equal(t, path, c.Get("path"))
}

func TestRouterNoRoutablePath(t *testing.T) {
e := New()
r := e.router
c := e.NewContext(nil, nil).(*context)

r.Find(http.MethodGet, "/notfound", c)
c.handler(c)

// No routable path, don't set Path.
assert.Equal(t, "", c.Path())
}

func TestRouterParam(t *testing.T) {
e := New()
r := e.router
Expand Down

0 comments on commit 08093a4

Please sign in to comment.