Merge e25867d2b4e5be7283a7cb2c0ef8418c621a5b0b into 51aea73ba0f125f6cacc3b4b695efdf21d9c634f

This commit is contained in:
atopx 2022-10-20 14:05:33 +08:00 committed by GitHub
commit 820ab8b694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -1210,7 +1210,7 @@ func (c *Context) Value(key any) any {
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 c.Request.Context().Value(key)

View File

@ -2354,3 +2354,11 @@ func TestContextAddParam(t *testing.T) {
assert.Equal(t, ok, true)
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)
}