From f2d31d59901cb33d3372d3a16601805d2f3bb8a2 Mon Sep 17 00:00:00 2001 From: Waleed AlMalki Date: Tue, 8 Oct 2019 15:59:24 +0300 Subject: [PATCH] Fixed multipart/form-data Content-Type detection --- cache.go | 9 ++++++++- decoder.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cache.go b/cache.go index 8d6aa9c..2a07b8c 100644 --- a/cache.go +++ b/cache.go @@ -504,7 +504,7 @@ func (c *cache) fieldAlias(field reflect.StructField, parentLocations []int, par if alias == "" { if tag, lTag := field.Tag.Get(nameTag), field.Tag.Get(fromTag); tag != "-" && lTag != "" { - locs := strings.Split(lTag, ",") + locs := clean(strings.Split(lTag, ",")) if len(locs) == 0 && len(parentLocations) > 0 { locations = parentLocations } else if len(locs) > 0 { @@ -607,3 +607,10 @@ func underlyingElem(t reflect.Type) reflect.Type { } return t } + +func clean(s []string) []string { + for i := range s { + s[i] = strings.TrimSpace(s[i]) + } + return s +} diff --git a/decoder.go b/decoder.go index b179128..b498194 100644 --- a/decoder.go +++ b/decoder.go @@ -150,7 +150,7 @@ func (d *Decoder) Decode(dst interface{}, r *http.Request) error { } func isMultipartForm(r *http.Request) bool { - return strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data;") + return strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data") } func isURLEncodedForm(r *http.Request) bool {