Skip to content

Commit

Permalink
Merge pull request #562 from runzhi/master
Browse files Browse the repository at this point in the history
fix: invalid unicode while binary to string
  • Loading branch information
taowen authored Jul 22, 2021
2 parents e6b9536 + 3c55efb commit c666182
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions extra/binary_as_string_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ func readHex(iter *jsoniter.Iterator, b1, b2 byte) byte {
}
ret *= 16
if b2 >= '0' && b2 <= '9' {
ret = b2 - '0'
ret += b2 - '0'
} else if b2 >= 'a' && b2 <= 'f' {
ret = b2 - 'a' + 10
ret += b2 - 'a' + 10
} else {
iter.ReportError("read hex", "expects 0~9 or a~f, but found "+string([]byte{b2}))
return 0
Expand Down
6 changes: 3 additions & 3 deletions extra/binary_as_string_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func TestBinaryAsStringCodec(t *testing.T) {
})
t.Run("non safe set", func(t *testing.T) {
should := require.New(t)
output, err := jsoniter.Marshal([]byte{1, 2, 3, 15})
output, err := jsoniter.Marshal([]byte{1, 2, 3, 23})
should.NoError(err)
should.Equal(`"\\x01\\x02\\x03\\x0f"`, string(output))
should.Equal(`"\\x01\\x02\\x03\\x17"`, string(output))
var val []byte
should.NoError(jsoniter.Unmarshal(output, &val))
should.Equal([]byte{1, 2, 3, 15}, val)
should.Equal([]byte{1, 2, 3, 23}, val)
})
}

0 comments on commit c666182

Please sign in to comment.