Repository: go-kratos/kratos
Pull request #2249 (2022-08-01 18:27:49)

build(deps): bump google.golang.org/protobuf from 1.28.0 to 1.28.1 in /contrib/log/aliyun
Bumps [google.golang.org/protobuf](https://github.com/protocolbuffers/protobuf-go) from 1.28.0 to 1.28.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/protocolbuffers/protobuf-go/releases">google.golang.org/protobuf's releases</a>.</em></p>
<blockquote>
<h2>v1.28.1</h2>
<p>This release contains protoc-gen-go binaries for arm64.</p>
<p>Notable changes since <a href="https://github.com/protocolbuffers/protobuf-go/releases/tag/v1.28.0">v1.28.0</a>:</p>
<ul>
<li><a href="https://golang.org/cl/418677">CL/418677</a>: internal/impl: improve MessageInfo.New performance</li>
<li><a href="https://golang.org/cl/411377">CL/411377</a>: proto: short-circuit Equal when inputs are identical</li>
<li><a href="https://golang.org/cl/419714">CL/419714</a>: all: Add prebuild binaries for arm64</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/6875c3d7242d1a3db910ce8a504f124cb840c23a"><code>6875c3d</code></a> all: release v1.28.1</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/881da6ece0696714305aee39afcac17b6abe8e00"><code>881da6e</code></a> all: Add prebuild binaries for arm64</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/2a74a0e82391d1fc344067bc6bfc4647cd8ae7d9"><code>2a74a0e</code></a> A+C: delete AUTHORS and CONTRIBUTORS</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/de9682ad1656cd1ee6808865f7a42f5a5d79eb73"><code>de9682a</code></a> internal/impl: improve MessageInfo.New performance</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/b0a944684d78a6b7c1f2bb6864fa910385d5b97a"><code>b0a9446</code></a> all: reformat with go1.19 gofmt</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/c1bbc5d45b2b8a056496c3db183b24e7f9a22ff1"><code>c1bbc5d</code></a> all: make integration test work on darwin/arm64</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/5f429f7042ff6743d1cd695281802b8c9b8d9395"><code>5f429f7</code></a> proto: fix compilation failure in tests</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/fc44d00d5a99973a6deb0863d6aaa7446c016066"><code>fc44d00</code></a> proto: use reflect.Ptr for backward compatibility</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/380c339ec12310c04cd1c399669ab0bce57b6cd6"><code>380c339</code></a> proto: short-circuit Equal when inputs are identical</li>
<li><a href="https://github.com/protocolbuffers/protobuf-go/commit/784c4825545540dc41a1dc85715d3251903bc8ce"><code>784c482</code></a> all: remove shorthand import aliases</li>
<li>Additional commits viewable in <a href="https://github.com/protocolbuffers/protobuf-go/compare/v1.28.0...v1.28.1">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=google.golang.org/protobuf&package-manager=go_modules&previous-version=1.28.0&new-version=1.28.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

codecov-commenter: # [Codecov](https://codecov.io/gh/go-kratos/kratos/pull/2249?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos) Report
> Merging [#2249](https://codecov.io/gh/go-kratos/kratos/pull/2249?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos) (85bf3c3) into [main](https://codecov.io/gh/go-kratos/kratos/commit/fea863e7837e808af0a1918cd1f8927fa76585aa?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos) (fea863e) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##             main    #2249   +/-   ##
=======================================
  Coverage   85.61%   85.61%           
=======================================
  Files          87       87           
  Lines        3789     3789           
=======================================
  Hits         3244     3244           
  Misses        378      378           
  Partials      167      167           
```



Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos).


Patch:
diff --git a/contrib/log/aliyun/go.mod b/contrib/log/aliyun/go.mod
index 8f0908ed..83b139ea 100644
--- a/contrib/log/aliyun/go.mod
+++ b/contrib/log/aliyun/go.mod
@@ -5,7 +5,7 @@ go 1.16
 require (
 	github.com/aliyun/aliyun-log-go-sdk v0.1.37
 	github.com/go-kratos/kratos/v2 v2.4.1
-	google.golang.org/protobuf v1.28.0
+	google.golang.org/protobuf v1.28.1
 )
 
 replace (
diff --git a/contrib/log/aliyun/go.sum b/contrib/log/aliyun/go.sum
index 91f02aea..6fde6344 100644
--- a/contrib/log/aliyun/go.sum
+++ b/contrib/log/aliyun/go.sum
@@ -462,8 +462,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
-google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
 google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
+google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
diff --git a/transport/http/binding/bind.go b/transport/http/binding/bind.go
index 3155d61e..10007367 100644
--- a/transport/http/binding/bind.go
+++ b/transport/http/binding/bind.go
@@ -4,13 +4,18 @@ import (
 	"net/http"
 	"net/url"
 
+	"github.com/go-kratos/kratos/v2/errors"
+
 	"github.com/go-kratos/kratos/v2/encoding"
 	"github.com/go-kratos/kratos/v2/encoding/form"
 )
 
 // BindQuery bind vars parameters to target.
 func BindQuery(vars url.Values, target interface{}) error {
-	return encoding.GetCodec(form.Name).Unmarshal([]byte(vars.Encode()), target)
+	if err := encoding.GetCodec(form.Name).Unmarshal([]byte(vars.Encode()), target); err != nil {
+		return errors.BadRequest("CODEC", err.Error())
+	}
+	return nil
 }
 
 // BindForm bind form parameters to target.
@@ -18,5 +23,8 @@ func BindForm(req *http.Request, target interface{}) error {
 	if err := req.ParseForm(); err != nil {
 		return err
 	}
-	return encoding.GetCodec(form.Name).Unmarshal([]byte(req.Form.Encode()), target)
+	if err := encoding.GetCodec(form.Name).Unmarshal([]byte(req.Form.Encode()), target); err != nil {
+		return errors.BadRequest("CODEC", err.Error())
+	}
+	return nil
 }


Test patch:
diff --git a/transport/http/binding/bind_test.go b/transport/http/binding/bind_test.go
index 5e2552f9..20aadba7 100644
--- a/transport/http/binding/bind_test.go
+++ b/transport/http/binding/bind_test.go
@@ -7,6 +7,8 @@ import (
 	"reflect"
 	"strings"
 	"testing"
+
+	"github.com/go-kratos/kratos/v2/errors"
 )
 
 func TestBindQuery(t *testing.T) {
@@ -14,7 +16,12 @@ func TestBindQuery(t *testing.T) {
 		Name string `json:"name"`
 		URL  string `json:"url"`
 	}
+
+	type TestBind2 struct {
+		Age int `json:"age"`
+	}
 	p1 := TestBind{}
+	p2 := TestBind2{}
 	type args struct {
 		vars   url.Values
 		target interface{}
@@ -34,11 +41,31 @@ func TestBindQuery(t *testing.T) {
 			wantErr: false,
 			want:    &TestBind{"kratos", "https://go-kratos.dev/"},
 		},
+		{
+			name: "test1",
+			args: args{
+				vars:   map[string][]string{"age": {"kratos"}, "url": {"https://go-kratos.dev/"}},
+				target: &p2,
+			},
+			wantErr: true,
+			want:    errors.BadRequest("CODEC", ""),
+		},
+		{
+			name: "test2",
+			args: args{
+				vars:   map[string][]string{"age": {"1"}, "url": {"https://go-kratos.dev/"}},
+				target: &TestBind2{},
+			},
+			wantErr: false,
+			want:    &TestBind2{Age: 1},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			if err := BindQuery(tt.args.vars, tt.args.target); (err != nil) != tt.wantErr {
 				t.Errorf("BindQuery() error = %v, wantErr %v", err, tt.wantErr)
+			} else {
+				t.Log(err)
 			}
 			if !tt.wantErr && !reflect.DeepEqual(tt.args.target, tt.want) {
 				t.Errorf("BindQuery() target = %v, want %v", tt.args.target, tt.want)
@@ -52,6 +79,9 @@ func TestBindForm(t *testing.T) {
 		Name string `json:"name"`
 		URL  string `json:"url"`
 	}
+	type TestBind2 struct {
+		Age int `json:"age"`
+	}
 	p1 := TestBind{}
 	type args struct {
 		req    *http.Request
@@ -85,6 +115,19 @@ func TestBindForm(t *testing.T) {
 			wantErr: false,
 			want:    &TestBind{"kratos", "https://go-kratos.dev/"},
 		},
+		{
+			name: "error BadRequest",
+			args: args{
+				req: &http.Request{
+					Method: "POST",
+					Header: http.Header{"Content-Type": {"application/x-www-form-urlencoded; param=value"}},
+					Body:   io.NopCloser(strings.NewReader("age=a")),
+				},
+				target: &TestBind2{},
+			},
+			wantErr: true,
+			want:    nil,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -92,6 +135,7 @@ func TestBindForm(t *testing.T) {
 			if (err != nil) != tt.wantErr {
 				t.Errorf("BindForm() error = %v, wantErr %v", err, tt.wantErr)
 			}
+			t.Log(err)
 			if !tt.wantErr && !reflect.DeepEqual(tt.args.target, tt.want) {
 				t.Errorf("BindForm() target = %v, want %v", tt.args.target, tt.want)
 			}