diff --git a/context.go b/context.go index b66b8adc..b86b54bb 100644 --- a/context.go +++ b/context.go @@ -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) diff --git a/context_test.go b/context_test.go index cc55cb01..a7ff3423 100644 --- a/context_test.go +++ b/context_test.go @@ -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) +}