github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/issue_test/issue119_test.go (about) 1 /* 2 * Copyright 2022 ByteDance Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package issue_test 18 19 import ( 20 "testing" 21 22 "encoding/json" 23 . "github.com/goshafaq/sonic" 24 "github.com/stretchr/testify/require" 25 ) 26 27 func TestIssue_UnmarshalBase64(t *testing.T) { 28 var obj, stdobj []byte 29 tests := []string{ 30 `"xy\r\nzu"`, 31 `"xy\/\/"`, 32 `"\/\/=="`, 33 `"\/\/\u003d\u003d"`, 34 `"\u0030\u0030\u0030\u003d"`, 35 } 36 for _, data := range tests { 37 stderr := json.Unmarshal([]byte(data), &stdobj) 38 err := Unmarshal([]byte(data), &obj) 39 require.NoError(t, stderr, data) 40 require.NoError(t, err, data) 41 require.Equal(t, stdobj, obj, data) 42 } 43 } 44 45 func TestIssue_UnmarshalBase64Error(t *testing.T) { 46 var obj, stdobj []byte 47 tests := []string{ 48 `"xy\r\nzu0==="`, 49 `"xy\/\/`, 50 `"\/\/==`, 51 `"\/\/\u003d0\u003d"`, 52 `"\u0030\u0030\u0030\u003d`, 53 } 54 for _, data := range tests { 55 stderr := json.Unmarshal([]byte(data), &stdobj) 56 err := Unmarshal([]byte(data), &obj) 57 require.Equal(t, stderr != nil, err != nil) 58 } 59 var _, _ = obj, stdobj 60 }