Skip to content

Commit

Permalink
Fixed multipart/form-data Content-Type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
wlMalk committed Oct 8, 2019
1 parent 5341c52 commit f2d31d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f2d31d5

Please sign in to comment.