Merge d39aabae8a0c26f795906e62fb5d5b908b765751 into 43fe48e8a0f44af783116cdb010725e6bb50255f

This commit is contained in:
Shantanav Mukherjee 2026-09-29 20:00:38 +05:30 committed by GitHub
commit f2306dae72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View File

@ -648,6 +648,9 @@ func (c *Context) initFormCache() {
if c.formCache == nil {
c.formCache = make(url.Values)
req := c.Request
if req == nil {
return
}
if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil {
if !errors.Is(err, http.ErrNotMultipart) {
debugPrint("error on parse multipart form array: %v", err)

View File

@ -927,6 +927,21 @@ func TestContextDefaultQueryOnEmptyRequest(t *testing.T) {
})
}
func TestContextPostFormOnEmptyRequest(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder()) // here c.Request == nil
assert.NotPanics(t, func() {
value, ok := c.GetPostForm("NoKey")
assert.False(t, ok)
assert.Empty(t, value)
})
assert.NotPanics(t, func() {
assert.Equal(t, "nada", c.DefaultPostForm("NoKey", "nada"))
})
assert.NotPanics(t, func() {
assert.Empty(t, c.PostForm("NoKey"))
})
}
func TestContextQueryAndPostForm(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder())
body := strings.NewReader("foo=bar&page=11&both=&foo=second")