mirror of
https://github.com/gin-gonic/gin.git
synced 2025-09-19 03:22:12 +08:00
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:
parent
b4c8bf1bbe
commit
d62987ea57
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user