Skip to content

Commit

Permalink
update1
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Dec 27, 2024
1 parent 18cb91c commit fa9acf8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
3 changes: 0 additions & 3 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,6 @@ func Test_Bind_Body(t *testing.T) {
writer := multipart.NewWriter(buf)
require.NoError(t, writer.WriteField("data[0][name]", "john"))
require.NoError(t, writer.WriteField("data[1][name]", "doe"))
require.NoError(t, writer.WriteField("data[1][names]", "john,doe"))
require.NoError(t, writer.Close())

c.Request().Header.SetContentType(writer.FormDataContentType())
Expand All @@ -1031,8 +1030,6 @@ func Test_Bind_Body(t *testing.T) {
require.Len(t, cq.Data, 2)
require.Equal(t, "john", cq.Data[0].Name)
require.Equal(t, "doe", cq.Data[1].Name)
require.Contains(t, cq.Data[1].Names, "john")
require.Contains(t, cq.Data[1].Names, "doe")
})

t.Run("CollectionQuerySquareBrackets", func(t *testing.T) {
Expand Down
14 changes: 5 additions & 9 deletions binder/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,25 @@ func (b *formBinding) BindMultipart(reqCtx *fasthttp.RequestCtx, out any) error
return err
}

temp := make(map[string][]string)
for key, values := range data.Value {
if strings.Contains(key, "[") {
k, err := parseParamSquareBrackets(key)
if err != nil {
return err
}
data.Value[k] = values
delete(data.Value, key) // Remove bracket notation and use dot instead

Check warning on line 67 in binder/form.go

View check run for this annotation

Codecov / codecov/patch

binder/form.go#L66-L67

Added lines #L66 - L67 were not covered by tests
key = k // We have to update key in case bracket notation and slice type are used at the same time
}

for _, v := range values {
if strings.Contains(v, ",") && equalFieldType(out, reflect.Slice, key) {
delete(data.Value, key)

values := strings.Split(v, ",")
for i := 0; i < len(values); i++ {
data.Value[key] = append(data.Value[key], values[i])
}
temp[key] = strings.Split(v, ",")
} else {
temp[key] = append(temp[key], v)

Check warning on line 75 in binder/form.go

View check run for this annotation

Codecov / codecov/patch

binder/form.go#L72-L75

Added lines #L72 - L75 were not covered by tests
}
}

Check warning on line 77 in binder/form.go

View check run for this annotation

Codecov / codecov/patch

binder/form.go#L77

Added line #L77 was not covered by tests
}

return parse(b.Name(), out, data.Value)
return parse(b.Name(), out, temp)
}

0 comments on commit fa9acf8

Please sign in to comment.