Repository: gin-gonic/gin
Pull request #3820 (2024-01-04 01:49:47)

fix(binding): binding error while not upload file (#3819)
- With pull requests:
  - Open your pull request against `master`
  - Your pull request should have no more than two commits, if not you should squash them.
  - It should pass all tests in the available continuous integration systems such as GitHub Actions.
  - You should add/modify tests to cover your proposed code changes.
  - If your pull request contains a new feature, please document it on the README.

fix: #3819 

clearcodecn: Is someone maintaining this warehouse? Why hasn't anyone replied to any issues or PR? 
appleboy: I will take it before https://github.com/gin-gonic/gin/pull/3834 merge
appleboy: @clearcodecn Please help to rebase the master branch
clearcodecn: @appleboy done, thank you.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/gin-gonic/gin/pull/3820?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`9f598a3`)](https://app.codecov.io/gh/gin-gonic/gin/commit/9f598a31aafb92d675f38f1c8371e4ac76f858bf?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) 99.21% compared to head [(`97d7376`)](https://app.codecov.io/gh/gin-gonic/gin/pull/3820?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) 99.21%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #3820   +/-   ##
=======================================
  Coverage   99.21%   99.21%           
=======================================
  Files          42       42           
  Lines        3180     3182    +2     
=======================================
+ Hits         3155     3157    +2     
  Misses         17       17           
  Partials        8        8           
```

| [Flag](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | Coverage Δ | |
|---|---|---|
| [](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | `99.21% <100.00%> (+<0.01%)` | :arrow_up: |
| [go-1.18](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | `99.12% <100.00%> (+<0.01%)` | :arrow_up: |
| [go-1.19](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | `99.21% <100.00%> (+<0.01%)` | :arrow_up: |
| [go-1.20](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | `99.21% <100.00%> (+<0.01%)` | :arrow_up: |
| [go-1.21](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | `99.21% <100.00%> (+<0.01%)` | :arrow_up: |
| [macos-latest](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | `99.21% <100.00%> (+<0.01%)` | :arrow_up: |
| [ubuntu-latest](https://app.codecov.io/gh/gin-gonic/gin/pull/3820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic) | `99.21% <100.00%> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic#carryforward-flags-in-the-pull-request-comment) to find out more.


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/gin-gonic/gin/pull/3820?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gin-gonic).


Patch:
diff --git a/binding/form_mapping.go b/binding/form_mapping.go
index 55435b9..77a1bde 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"
@@ -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:


Test patch:
diff --git a/binding/form_mapping_test.go b/binding/form_mapping_test.go
index acea8f7..16527eb 100644
--- a/binding/form_mapping_test.go
+++ b/binding/form_mapping_test.go
@@ -5,6 +5,7 @@
 package binding
 
 import (
+	"mime/multipart"
 	"reflect"
 	"testing"
 	"time"
@@ -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()