fix(route): Add fullPath in context copy (#3784)

* fix: Add fullPath in context copy

* Update context.go

---------

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Karthik Reddy Puli 2024-03-06 14:16:53 +05:30 committed by GitHub
parent f75144a356
commit 09f8224593
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 0 deletions

View File

@ -120,6 +120,7 @@ func (c *Context) Copy() *Context {
cp.Writer = &cp.writermem cp.Writer = &cp.writermem
cp.index = abortIndex cp.index = abortIndex
cp.handlers = nil cp.handlers = nil
cp.fullPath = c.fullPath
cKeys := c.Keys cKeys := c.Keys
cp.Keys = make(map[string]any, len(cKeys)) cp.Keys = make(map[string]any, len(cKeys))

View File

@ -324,6 +324,7 @@ func TestContextCopy(t *testing.T) {
c.handlers = HandlersChain{func(c *Context) {}} c.handlers = HandlersChain{func(c *Context) {}}
c.Params = Params{Param{Key: "foo", Value: "bar"}} c.Params = Params{Param{Key: "foo", Value: "bar"}}
c.Set("foo", "bar") c.Set("foo", "bar")
c.fullPath = "/hola"
cp := c.Copy() cp := c.Copy()
assert.Nil(t, cp.handlers) assert.Nil(t, cp.handlers)
@ -336,6 +337,7 @@ func TestContextCopy(t *testing.T) {
assert.Equal(t, cp.Params, c.Params) assert.Equal(t, cp.Params, c.Params)
cp.Set("foo", "notBar") cp.Set("foo", "notBar")
assert.False(t, cp.Keys["foo"] == c.Keys["foo"]) assert.False(t, cp.Keys["foo"] == c.Keys["foo"])
assert.Equal(t, cp.fullPath, c.fullPath)
} }
func TestContextHandlerName(t *testing.T) { func TestContextHandlerName(t *testing.T) {