Selaa lähdekoodia

\n should not be ignored in base64 decode

Tao Wen 7 vuotta sitten
vanhempi
commit
8744d7c5c7
2 muutettua tiedostoa jossa 15 lisäystä ja 2 poistoa
  1. 13 1
      misc_tests/jsoniter_array_test.go
  2. 2 1
      reflect_native.go

+ 13 - 1
misc_tests/jsoniter_array_test.go

@@ -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{}

+ 2 - 1
reflect_native.go

@@ -2,10 +2,11 @@ package jsoniter
 
 import (
 	"encoding/base64"
-	"github.com/modern-go/reflect2"
 	"reflect"
 	"strconv"
 	"unsafe"
+
+	"github.com/modern-go/reflect2"
 )
 
 const ptrSize = 32 << uintptr(^uintptr(0)>>63)