mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
Merge e25867d2b4e5be7283a7cb2c0ef8418c621a5b0b into 51aea73ba0f125f6cacc3b4b695efdf21d9c634f
This commit is contained in:
commit
820ab8b694
@ -1210,7 +1210,7 @@ func (c *Context) Value(key any) any {
|
|||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !c.engine.ContextWithFallback || c.Request == nil || c.Request.Context() == nil {
|
if c.engine == nil || !c.engine.ContextWithFallback || c.Request == nil || c.Request.Context() == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return c.Request.Context().Value(key)
|
return c.Request.Context().Value(key)
|
||||||
|
@ -2354,3 +2354,11 @@ func TestContextAddParam(t *testing.T) {
|
|||||||
assert.Equal(t, ok, true)
|
assert.Equal(t, ok, true)
|
||||||
assert.Equal(t, value, v)
|
assert.Equal(t, value, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextValue(t *testing.T) {
|
||||||
|
c := &Context{}
|
||||||
|
id := "id"
|
||||||
|
// gin@v1.8.1 will panic
|
||||||
|
value := c.Value(id)
|
||||||
|
assert.Nil(t, value)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user