From 9ef94ad46b3fd90201f445bf0e3b33135d97cc7e Mon Sep 17 00:00:00 2001 From: withchao <48119764+withchao@users.noreply.github.com> Date: Mon, 24 Jul 2023 18:07:31 +0800 Subject: [PATCH] fix: StringValue When there are double quotes in the string value, serialization and deserialization fail (#646) Signed-off-by: withchao <993506633@qq.com> --- pkg/proto/wrapperspb/wrapperspb.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/proto/wrapperspb/wrapperspb.go b/pkg/proto/wrapperspb/wrapperspb.go index 7579c64f0..b7d4b0c31 100644 --- a/pkg/proto/wrapperspb/wrapperspb.go +++ b/pkg/proto/wrapperspb/wrapperspb.go @@ -16,6 +16,7 @@ package wrapperspb import ( "encoding/base64" + "encoding/json" "errors" "strconv" ) @@ -211,15 +212,11 @@ func (m *BoolValue) MarshalJSON() ([]byte, error) { } func (m *StringValue) UnmarshalJSON(p []byte) error { - if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' { - return errors.New("invalid string value") - } - m.Value = string(p[1 : len(p)-1]) - return nil + return json.Unmarshal(p, &m.Value) } func (m *StringValue) MarshalJSON() ([]byte, error) { - return []byte(`"` + m.Value + `"`), nil + return json.Marshal(m.Value) } func (m *BytesValue) UnmarshalJSON(p []byte) error {