From 40ae3d31cdf30e35e3822d40d1e125776b47ce2d Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Mon, 24 Jul 2023 17:49:59 +0800 Subject: [PATCH] fix: StringValue When there are double quotes in the string value, serialization and deserialization fail --- 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 {