gojay

high performance JSON encoder/decoder with stream API for Golang
git clone git://git.lair.cx/gojay
Log | Files | Refs | README | LICENSE

commit da3273f11d000b2f16297899d701d41c80c07a26
parent ef10bf36a252f8bda1248cedda106996f6512379
Author: francoispqt <francois@parquet.ninja>
Date:   Wed,  5 Dec 2018 11:33:49 +0800

fix error when skipping unicode string

Diffstat:
Mdecode_string.go | 3+++
Mdecode_string_test.go | 12++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/decode_string.go b/decode_string.go @@ -178,6 +178,9 @@ func (dec *Decoder) skipEscapedString() error { return dec.raiseInvalidJSONErr(dec.cursor) } return nil + case 'u': + // is unicode + return dec.skipString() case 'n', 'r', 't', '/', 'f', 'b': return nil default: diff --git a/decode_string_test.go b/decode_string_test.go @@ -738,10 +738,15 @@ func TestSkipString(t *testing.T) { expectedResult: "", err: false, }, + { + name: "string-unicode", + json: `[2]\u66fe\u5b97\u5357"`, + expectedResult: "", + err: false, + }, } for _, testCase := range testCases { - str := "" dec := NewDecoder(strings.NewReader(testCase.json)) err := dec.skipString() if testCase.err { @@ -749,9 +754,8 @@ func TestSkipString(t *testing.T) { if testCase.errType != nil { assert.IsType(t, testCase.errType, err, "err should be of expected type") } - } else { - assert.Nil(t, err, "err should be nil") + return } - assert.Equal(t, testCase.expectedResult, str, fmt.Sprintf("str should be equal to '%s'", testCase.expectedResult)) + assert.Nil(t, err, "err should be nil") } }