1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

fix base64 contains newline characters \r or \n

This commit is contained in:
ceshihao
2018-04-23 23:10:55 +08:00
parent 6c702ce12a
commit 6a6742f0a2
2 changed files with 20 additions and 2 deletions

View File

@ -3,9 +3,10 @@ package misc_tests
import (
"bytes"
"encoding/json"
"testing"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"testing"
)
func Test_empty_array(t *testing.T) {
@ -168,6 +169,17 @@ func Test_decode_byte_array_from_base64(t *testing.T) {
should.Equal([]byte{1, 2, 3}, data)
}
func Test_decode_byte_array_from_base64_with_newlines(t *testing.T) {
should := require.New(t)
data := []byte{}
err := json.Unmarshal([]byte(`"A\rQ\nID"`), &data)
should.Nil(err)
should.Equal([]byte{1, 2, 3}, data)
err = jsoniter.Unmarshal([]byte(`"A\rQ\nID"`), &data)
should.Nil(err)
should.Equal([]byte{1, 2, 3}, data)
}
func Test_decode_byte_array_from_array(t *testing.T) {
should := require.New(t)
data := []byte{}