Skip to content

Commit

Permalink
fix: ignore empty form values in http request
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Jan 10, 2025
1 parent fa46746 commit 5b2e3b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rest/httpx/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestParseFormArray(t *testing.T) {
http.NoBody)
assert.NoError(t, err)
if assert.NoError(t, Parse(r, &v)) {
assert.ElementsMatch(t, []string{""}, v.Name)
assert.Empty(t, v.Name)
}
})

Expand All @@ -129,7 +129,7 @@ func TestParseFormArray(t *testing.T) {
http.NoBody)
assert.NoError(t, err)
if assert.NoError(t, Parse(r, &v)) {
assert.ElementsMatch(t, []string{"", "1"}, v.Name)
assert.ElementsMatch(t, []string{"1"}, v.Name)
}
})

Expand Down
4 changes: 4 additions & 0 deletions rest/httpx/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ 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 {
if len(v) == 0 {
continue
}

if n < maxFormParamCount {
filtered = append(filtered, v)
n++
Expand Down

0 comments on commit 5b2e3b6

Please sign in to comment.