fix: ignore empty form values in http request (#4542)

This commit is contained in:
Kevin Wan
2025-01-13 01:03:32 +08:00
committed by GitHub
parent 024f285f86
commit 11c47d23df
2 changed files with 87 additions and 2 deletions

View File

@@ -35,6 +35,16 @@ func GetFormValues(r *http.Request) (map[string]any, error) {
for name, values := range r.Form {
filtered := make([]string, 0, len(values))
for _, v := range values {
// ignore empty values, especially for optional int parameters
// e.g. /api?ids=
// e.g. /api
// type Req struct {
// IDs []int `form:"ids,optional"`
// }
if len(v) == 0 {
continue
}
if n < maxFormParamCount {
filtered = append(filtered, v)
n++