From 0e1e6d6ee893b44558cd153d292362ba178785d6 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Fri, 31 Jul 2026 21:23:02 +0800 Subject: [PATCH] fix: prevent nil pointer panic in PostForm getters when Context has no request --- context.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/context.go b/context.go index 1dc730e3..b3b2ad62 100644 --- a/context.go +++ b/context.go @@ -647,14 +647,18 @@ func (c *Context) PostFormArray(key string) (values []string) { func (c *Context) initFormCache() { if c.formCache == nil { - c.formCache = make(url.Values) - req := c.Request - if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil { - if !errors.Is(err, http.ErrNotMultipart) { - debugPrint("error on parse multipart form array: %v", err) + if c.Request != nil { + c.formCache = make(url.Values) + req := c.Request + if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil { + if !errors.Is(err, http.ErrNotMultipart) { + debugPrint("error on parse multipart form array: %v", err) + } } + c.formCache = req.PostForm + } else { + c.formCache = url.Values{} } - c.formCache = req.PostForm } }