Skip to content
Snippets Groups Projects
Commit f6595e99 authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Proper support for CSV parsing in param values written as ["123","456"]

parent 84b562be
Branches
Tags
No related merge requests found
package api
import (
"encoding/csv"
"encoding/json"
"reflect"
"strings"
......@@ -101,7 +102,12 @@ func (ctx apiContext) extract(name string, t reflect.Type, v reflect.Value) erro
var paramStrValues []string
if paramStrValue, isDefined := ctx.request.QueryStringParameters[n]; isDefined {
if len(paramStrValue) >= 2 && paramStrValue[0] == '[' && paramStrValue[len(paramStrValue)-1] == ']' {
paramStrValues = strings.Split(paramStrValue[1:len(paramStrValue)-1], ",") //from [CSV]
csvReader := csv.NewReader(strings.NewReader(paramStrValue))
var err error
paramStrValues, err = csvReader.Read()
if err != nil {
return errors.Wrapf(err, "invalid CSV")
}
} else {
paramStrValues = []string{paramStrValue} //single value
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment