From b8cfe5ae4d4d425fa941ebf8cb9cba1a8b073f3f Mon Sep 17 00:00:00 2001 From: Jo YoHan Date: Thu, 15 Aug 2024 14:13:17 +0900 Subject: [PATCH] feat(form): add array collection format in form binding --- binding/form_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index 93d3ca2ab5..4a35866da2 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -202,7 +202,11 @@ func trySplit(vs []string, field reflect.StructField) (newVs []string, err error return vs, fmt.Errorf("%s is not supported in the collection_format. (csv, ssv, pipes)", cfTag) } - newVs = make([]string, 0) + totalLength := 0 + for _, v := range vs { + totalLength += strings.Count(v, sep) + 1 + } + newVs = make([]string, 0, totalLength) for _, v := range vs { newVs = append(newVs, strings.Split(v, sep)...) }