Merge 7cdb8065f4809bab29a3a6d55bbd98058671f1d0 into 51aea73ba0f125f6cacc3b4b695efdf21d9c634f

This commit is contained in:
Jean-Baptiste Le Duigou 2022-10-20 08:03:13 +09:00 committed by GitHub
commit 55545bc648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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)

View File

@ -2354,3 +2354,9 @@ 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 TestRetrieveValueNoEngineInContext(t *testing.T) {
c := &Context{}
v := c.Value("foo")
assert.Nil(t, v)
}