From d62987ea57b997f067b1ab4c3083b4c30fb15973 Mon Sep 17 00:00:00 2001 From: alireza Date: Sun, 17 May 2020 15:06:11 +0430 Subject: [PATCH] Fix the issue of returning validation error instead of json.SyntaxError on a required upload file field inside an HTML form Fix case order hence the fallthrough works like expected. --- binding/form_mapping.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index b81ad195..e78c0512 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -7,6 +7,7 @@ package binding import ( "errors" "fmt" + "mime/multipart" "reflect" "strconv" "strings" @@ -157,6 +158,11 @@ func setByForm(value reflect.Value, field reflect.StructField, form map[string][ return false, fmt.Errorf("%q is not valid value for %s", vs, value.Type().String()) } return true, setArray(vs, value, field) + case reflect.Struct: + if _, ok := value.Interface().(multipart.FileHeader); ok && value.IsZero() { + return false, nil + } + fallthrough default: var val string if !ok {