Merge d39aabae8a0c26f795906e62fb5d5b908b765751 into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646

This commit is contained in:
Shantanav Mukherjee 2026-10-10 17:03:40 +05:30 committed by GitHub
commit f02c47173b
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")