-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deal with unescaped char in string as prev
- Loading branch information
Showing
9 changed files
with
29,860 additions
and
29,654 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29,928 changes: 14,999 additions & 14,929 deletions
29,928
internal/native/avx2/parse_with_padding_text_amd64.go
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29,437 changes: 14,792 additions & 14,645 deletions
29,437
internal/native/sse/parse_with_padding_text_amd64.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package sonic_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"strings" | ||
|
||
"github.com/bytedance/sonic" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUnescapedCharInString(t *testing.T) { | ||
var data = "\"" + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" + "\"" | ||
|
||
t.Run("Default", func(t *testing.T) { | ||
var sonicv, jsonv string | ||
sonice := sonic.Unmarshal([]byte(data), &sonicv) | ||
assert.NoError(t, sonice) | ||
assert.Equal(t, sonicv, data[1:len(data) - 1]) | ||
|
||
jsone := json.Unmarshal([]byte(data), &jsonv) | ||
assert.True(t, strings.Contains(jsone.Error(), ("invalid char"))) | ||
assert.Equal(t, jsonv, "") | ||
}) | ||
|
||
t.Run("ValidateString", func(t *testing.T) { | ||
var sonicv, jsonv string | ||
api := sonic.Config { | ||
ValidateString: true, | ||
}.Froze() | ||
sonice := api.Unmarshal([]byte(data), &sonicv) | ||
assert.True(t, strings.Contains(sonice.Error(), ("invalid char"))) | ||
assert.Equal(t, sonicv, "") | ||
|
||
jsone := json.Unmarshal([]byte(data), &jsonv) | ||
assert.True(t, strings.Contains(jsone.Error(), ("invalid char"))) | ||
assert.Equal(t, jsonv, "") | ||
}) | ||
} |