From ad613c3550cd9c77e1a6283b8f25ef5f103cf881 Mon Sep 17 00:00:00 2001 From: William Poussier Date: Tue, 29 Jan 2019 11:16:14 +0100 Subject: [PATCH] tonic/handler: use strconv.ParseBool to interpret the Explode Tag, with true as default value. --- tonic/handler.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tonic/handler.go b/tonic/handler.go index 0da9228..18ea0a3 100644 --- a/tonic/handler.go +++ b/tonic/handler.go @@ -4,6 +4,7 @@ import ( "fmt" "reflect" "runtime" + "strconv" "strings" "sync" @@ -194,11 +195,11 @@ func bind(c *gin.Context, v reflect.Value, tag string, extract extractor) error } // Set-up context for extractors. // Query. - explode, ok := ft.Tag.Lookup(ExplodeTag) - if ok && explode == "false" { - c.Set(ExplodeTag, false) - } else { - c.Set(ExplodeTag, true) + c.Set(ExplodeTag, true) // default + if explodeVal, ok := ft.Tag.Lookup(ExplodeTag); ok { + if explode, err := strconv.ParseBool(explodeVal); err == nil && !explode { + c.Set(ExplodeTag, false) + } } _, fieldValues, err := extract(c, tagValue) if err != nil {