Merge pull request #348 from V02460/json_string

Encode \b and \f in JSON string as themselves
This commit is contained in:
Josh Baker 2024-02-14 19:46:13 -07:00 committed by GitHub
commit 711c6fe9ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View File

@ -1926,6 +1926,10 @@ func AppendJSONString(dst []byte, s string) []byte {
if s[i] < ' ' {
dst = append(dst, '\\')
switch s[i] {
case '\b':
dst = append(dst, 'b')
case '\f':
dst = append(dst, 'f')
case '\n':
dst = append(dst, 'n')
case '\r':

View File

@ -2578,6 +2578,7 @@ func TestJSONString(t *testing.T) {
testJSONString(t, s)
testJSONString(t, "R\xfd\xfc\a!\x82eO\x16?_\x0f\x9ab\x1dr")
testJSONString(t, "_\xb9\v\xad\xb3|X!\xb6\xd9U&\xa4\x1a\x95\x04")
testJSONString(t, "\b\f")
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
start := time.Now()
var buf [16]byte