Skip to content

Commit c666182

Browse files
authored
Merge pull request #562 from runzhi/master
fix: invalid unicode while binary to string
2 parents e6b9536 + 3c55efb commit c666182

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

extra/binary_as_string_codec.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ func readHex(iter *jsoniter.Iterator, b1, b2 byte) byte {
180180
}
181181
ret *= 16
182182
if b2 >= '0' && b2 <= '9' {
183-
ret = b2 - '0'
183+
ret += b2 - '0'
184184
} else if b2 >= 'a' && b2 <= 'f' {
185-
ret = b2 - 'a' + 10
185+
ret += b2 - 'a' + 10
186186
} else {
187187
iter.ReportError("read hex", "expects 0~9 or a~f, but found "+string([]byte{b2}))
188188
return 0

extra/binary_as_string_codec_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func TestBinaryAsStringCodec(t *testing.T) {
2222
})
2323
t.Run("non safe set", func(t *testing.T) {
2424
should := require.New(t)
25-
output, err := jsoniter.Marshal([]byte{1, 2, 3, 15})
25+
output, err := jsoniter.Marshal([]byte{1, 2, 3, 23})
2626
should.NoError(err)
27-
should.Equal(`"\\x01\\x02\\x03\\x0f"`, string(output))
27+
should.Equal(`"\\x01\\x02\\x03\\x17"`, string(output))
2828
var val []byte
2929
should.NoError(jsoniter.Unmarshal(output, &val))
30-
should.Equal([]byte{1, 2, 3, 15}, val)
30+
should.Equal([]byte{1, 2, 3, 23}, val)
3131
})
3232
}

0 commit comments

Comments
 (0)