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.
This commit is contained in:
alireza 2020-05-17 15:06:11 +04:30
parent b4c8bf1bbe
commit d62987ea57

View File

@ -7,6 +7,7 @@ package binding
import ( import (
"errors" "errors"
"fmt" "fmt"
"mime/multipart"
"reflect" "reflect"
"strconv" "strconv"
"strings" "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 false, fmt.Errorf("%q is not valid value for %s", vs, value.Type().String())
} }
return true, setArray(vs, value, field) return true, setArray(vs, value, field)
case reflect.Struct:
if _, ok := value.Interface().(multipart.FileHeader); ok && value.IsZero() {
return false, nil
}
fallthrough
default: default:
var val string var val string
if !ok { if !ok {