fix: StringValue When there are double quotes in the string value, serialization and deserialization fail (#646)

Signed-off-by: withchao <993506633@qq.com>
pull/648/head
withchao 1 year ago committed by GitHub
parent 00b4483065
commit 9ef94ad46b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,7 @@ package wrapperspb
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json"
"errors" "errors"
"strconv" "strconv"
) )
@ -211,15 +212,11 @@ func (m *BoolValue) MarshalJSON() ([]byte, error) {
} }
func (m *StringValue) UnmarshalJSON(p []byte) error { func (m *StringValue) UnmarshalJSON(p []byte) error {
if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' { return json.Unmarshal(p, &m.Value)
return errors.New("invalid string value")
}
m.Value = string(p[1 : len(p)-1])
return nil
} }
func (m *StringValue) MarshalJSON() ([]byte, error) { func (m *StringValue) MarshalJSON() ([]byte, error) {
return []byte(`"` + m.Value + `"`), nil return json.Marshal(m.Value)
} }
func (m *BytesValue) UnmarshalJSON(p []byte) error { func (m *BytesValue) UnmarshalJSON(p []byte) error {

Loading…
Cancel
Save