Repository: go-kratos/kratos
Pull request #1991 (2022-05-17 16:58:48)

feat: decode google.protobuf.BytesValue compatible base64.URLEncoding.
<!--
🎉 Thanks for sending a pull request to Kratos! Here are some tips for you:

1. If this is your first time contributing to Kratos, please read our contribution guide: https://go-kratos.dev/en/docs/community/contribution/
2. Ensure you have added or ran the appropriate tests and lint for your PR, please use `make lint` and `make test` before filing your PR, use `make clean` to tidy your go mod.
3. If the PR is unfinished, you may need mark it as a WIP(Work In Progress) PR or draft PR
4. Please use a conventional commits format title: `<type>[optional scope]: <description>`
    
    Some suggestion on <type>:

    fix: A bug fix
    feat: A new feature
    test: Adding missing tests or correcting existing tests
    refactor: A code change that neither fixes a bug nor adds a feature
    break: Changes has break change

    docs: Documentation only changes
    deps: Changes external dependencies
    style: Changes that do not affect the meaning of the code (white-space, formatting, etc)
    chore Daily work, examples, etc.
    ci: Changes to our CI configuration files and scripts
-->

#### Description (what this PR does / why we need it):
<!--
* The description should include the motivation for this PR or contrast this with previous behavior
-->
 It can not decode  the correct URL  from base64.URLEncoding


<!--
* Automatically closes linked issue when PR is merged.
* If you PR is not fully resolved issue, please use `part of #<issue number>` instead.

Usage: `fixes/resolves #<issue number>`, or `fixes/resolves (paste link of issue)`.
-->



<!--
* Somethings that need extra attention for reviewer
* Some additional notes, TODO list, etc.
-->



Patch:
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index f2bb809a..4e4e2061 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -3,22 +3,8 @@
 
 1. If this is your first time contributing to Kratos, please read our contribution guide: https://go-kratos.dev/en/docs/community/contribution/
 2. Ensure you have added or ran the appropriate tests and lint for your PR, please use `make lint` and `make test` before filing your PR, use `make clean` to tidy your go mod.
-3. If the PR is unfinished, you may need mark it as a WIP(Work In Progress) PR or draft PR
-4. Please use a conventional commits format title: `<type>[optional scope]: <description>`
-    
-    Some suggestion on <type>:
-
-    fix: A bug fix
-    feat: A new feature
-    test: Adding missing tests or correcting existing tests
-    refactor: A code change that neither fixes a bug nor adds a feature
-    break: Changes has break change
-
-    docs: Documentation only changes
-    deps: Changes external dependencies
-    style: Changes that do not affect the meaning of the code (white-space, formatting, etc)
-    chore Daily work, examples, etc.
-    ci: Changes to our CI configuration files and scripts
+3. If the PR is unfinished, you may need to mark it as a WIP(Work In Progress) PR or draft PR
+4. Please use a semantic commits format title, such as `<type>[optional scope]: <description>`, see: https://go-kratos.dev/docs/community/contribution#type
 -->
 
 #### Description (what this PR does / why we need it):
@@ -30,14 +16,14 @@
 #### Which issue(s) this PR fixes (resolves / be part of):
 <!--
 * Automatically closes linked issue when PR is merged.
-* If you PR is not fully resolved issue, please use `part of #<issue number>` instead.
+* If your PR is not fully resolved the issue, please use `part of #<issue number>` instead.
 
 Usage: `fixes/resolves #<issue number>`, or `fixes/resolves (paste link of issue)`.
 -->
-fixes #
 
-#### Other special notes for reviewer:
+
+#### Other special notes for the reviewers:
 <!--
-* Somethings that need extra attention for reviewer
+* Somethings that need extra attention for the reviewers
 * Some additional notes, TODO list, etc.
--->
+-->
\ No newline at end of file
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 4d5c5f2f..86762082 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -13,7 +13,7 @@ jobs:
   build:
     strategy:
       matrix:
-        go: [ 1.16, 1.17, 1.18 ]
+        go: [1.16, 1.17, 1.18]
     name: build & test
     runs-on: ubuntu-latest
     services:
@@ -35,11 +35,6 @@ jobs:
         ports:
           - "8848:8848"
           - "9848:9848"
-      polaris:
-        image: huyuanxin/polaris-server-with-config:latest
-        ports:
-          - 8090:8090
-          - 8091:8091
     steps:
       - uses: actions/checkout@v2
       - name: Set up Go
diff --git a/encoding/form/proto_decode.go b/encoding/form/proto_decode.go
index 8b4b3159..9e31e3ba 100644
--- a/encoding/form/proto_decode.go
+++ b/encoding/form/proto_decode.go
@@ -283,7 +283,9 @@ func parseMessage(md protoreflect.MessageDescriptor, value string) (protoreflect
 	case "google.protobuf.BytesValue":
 		v, err := base64.StdEncoding.DecodeString(value)
 		if err != nil {
-			return protoreflect.Value{}, err
+			if v, err = base64.URLEncoding.DecodeString(value); err != nil {
+				return protoreflect.Value{}, err
+			}
 		}
 		msg = wrapperspb.Bytes(v)
 	case "google.protobuf.FieldMask":


Test patch:
diff --git a/contrib/registry/consul/registry_test.go b/contrib/registry/consul/registry_test.go
index 82b7b041..e6b85e7d 100644
--- a/contrib/registry/consul/registry_test.go
+++ b/contrib/registry/consul/registry_test.go
@@ -57,10 +57,6 @@ func TestRegister(t *testing.T) {
 	}
 	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
 	defer cancel()
-	err = r.Deregister(ctx, svc)
-	if err != nil {
-		t.Errorf("Deregister failed: %v", err)
-	}
 	err = r.Register(ctx, svc)
 	if err != nil {
 		t.Errorf("Register failed: %v", err)
@@ -86,6 +82,10 @@ func TestRegister(t *testing.T) {
 	if !reflect.DeepEqual(version, services[0].Version) {
 		t.Errorf("no expect float_key value: %v, but got: %v", services[0].Version, version)
 	}
+	err = r.Deregister(ctx, svc)
+	if err != nil {
+		t.Errorf("Deregister failed: %v", err)
+	}
 }
 
 func getIntranetIP() string {
diff --git a/encoding/form/form_test.go b/encoding/form/form_test.go
index f437ddf1..384869c5 100644
--- a/encoding/form/form_test.go
+++ b/encoding/form/form_test.go
@@ -1,6 +1,7 @@
 package form
 
 import (
+	"encoding/base64"
 	"reflect"
 	"testing"
 
@@ -178,3 +179,16 @@ func TestDecodeStructPb(t *testing.T) {
 		t.Errorf("except %v, got %v", "go-kratos", req.Data.GetFields()["name2"].GetStringValue())
 	}
 }
+
+func TestDecodeBytesValuePb(t *testing.T) {
+	url := "https://example.com/xx/?a=1&b=2&c=3"
+	val := base64.URLEncoding.EncodeToString([]byte(url))
+	content := "bytes=" + val
+	in2 := &complex.Complex{}
+	if err := encoding.GetCodec(contentType).Unmarshal([]byte(content), in2); err != nil {
+		t.Errorf("expect %v, got %v", nil, err)
+	}
+	if !reflect.DeepEqual(url, string(in2.Bytes.Value)) {
+		t.Errorf("except %v, got %v", val, string(in2.Bytes.Value))
+	}
+}
diff --git a/hack/.test_ignored_files b/hack/.test_ignored_files
index 52d736ef..baada5c1 100644
--- a/hack/.test_ignored_files
+++ b/hack/.test_ignored_files
@@ -5,6 +5,5 @@
 ./contrib/config/kubernetes
 ./contrib/registry/kubernetes
 ./contrib/registry/zookeeper
-./contrib/registry/etcd
-./contrib/registry/consul
 ./contrib/registry/eureka
+./contrib/registry/polaris