1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-15 01:34:53 +02:00

Tested and fixed bug with reused context (path parameters).

This commit is contained in:
Ole Bulbuk
2017-03-30 12:05:24 +02:00
parent 22012e0e9d
commit f0e3f950cf
3 changed files with 30 additions and 18 deletions

View File

@ -296,18 +296,18 @@ func (n *node) checkMethodNotAllowed() HandlerFunc {
// - Get context from `Echo#AcquireContext()`
// - Reset it `Context#Reset()`
// - Return it `Echo#ReleaseContext()`.
func (r *Router) Find(method, path string, context Context) {
context.SetPath(path)
func (r *Router) Find(method, path string, ctx Context) {
ctx.SetPath(path)
cn := r.tree // Current node as root
var (
search = path
c *node // Child node
n int // Param counter
nk kind // Next kind
nn *node // Next node
ns string // Next search
pvalues = context.ParamValues()
c *node // Child node
n int // Param counter
nk kind // Next kind
nn *node // Next node
ns string // Next search
pvalues = ctx.(*context).pvalues // use the internal slice so the interface can keep the illusion of a dynamic slice
)
// Search order static > param > any
@ -409,13 +409,13 @@ func (r *Router) Find(method, path string, context Context) {
}
End:
context.SetHandler(cn.findHandler(method))
context.SetPath(cn.ppath)
context.SetParamNames(cn.pnames...)
ctx.SetHandler(cn.findHandler(method))
ctx.SetPath(cn.ppath)
ctx.SetParamNames(cn.pnames...)
// NOTE: Slow zone...
if context.Handler() == nil {
context.SetHandler(cn.checkMethodNotAllowed())
if ctx.Handler() == nil {
ctx.SetHandler(cn.checkMethodNotAllowed())
// Dig further for any, might have an empty value for *, e.g.
// serving a directory. Issue #207.
@ -423,12 +423,12 @@ End:
return
}
if h := cn.findHandler(method); h != nil {
context.SetHandler(h)
ctx.SetHandler(h)
} else {
context.SetHandler(cn.checkMethodNotAllowed())
ctx.SetHandler(cn.checkMethodNotAllowed())
}
context.SetPath(cn.ppath)
context.SetParamNames(cn.pnames...)
ctx.SetPath(cn.ppath)
ctx.SetParamNames(cn.pnames...)
pvalues[len(cn.pnames)-1] = ""
}