\n should not be ignored in base64 decode

This commit is contained in:
Tao Wen committed 2018-05-26 09:43:29 +08:00
commit 8744d7c5c7
2 files changed
+15 -2

No files matched your search

+13 -1
View File
@@ -3,9 +3,10 @@ package misc_tests
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"testing"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing"
) )
func Test_empty_array(t *testing.T) { 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) 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) { func Test_decode_byte_array_from_array(t *testing.T) {
should := require.New(t) should := require.New(t)
data := []byte{} data := []byte{}
+2 -1
View File
@@ -2,10 +2,11 @@ package jsoniter
import ( import (
"encoding/base64" "encoding/base64"
"github.com/modern-go/reflect2"
"reflect" "reflect"
"strconv" "strconv"
"unsafe" "unsafe"
"github.com/modern-go/reflect2"
) )
const ptrSize = 32 << uintptr(^uintptr(0)>>63) const ptrSize = 32 << uintptr(^uintptr(0)>>63)