Skip to content

Commit

Permalink
fix(binding): binding error while not upload file (#3819) (#3820)
Browse files Browse the repository at this point in the history
Co-authored-by: zhangmj <zhangmj1@dustess.com>
  • Loading branch information
clearcodecn and zhangmj authored Feb 5, 2024
1 parent 9f598a3 commit 3dc1cd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions binding/form_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package binding
import (
"errors"
"fmt"
"mime/multipart"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -235,6 +236,8 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel
switch value.Interface().(type) {
case time.Time:
return setTimeField(val, field, value)
case multipart.FileHeader:
return nil
}
return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())
case reflect.Map:
Expand Down
2 changes: 2 additions & 0 deletions binding/form_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package binding

import (
"mime/multipart"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -43,6 +44,7 @@ func TestMappingBaseTypes(t *testing.T) {
{"zero value", struct{ F uint }{}, "", uint(0)},
{"zero value", struct{ F bool }{}, "", false},
{"zero value", struct{ F float32 }{}, "", float32(0)},
{"file value", struct{ F *multipart.FileHeader }{}, "", &multipart.FileHeader{}},
} {
tp := reflect.TypeOf(tt.value)
testName := tt.name + ":" + tp.Field(0).Type.String()
Expand Down

0 comments on commit 3dc1cd6

Please sign in to comment.