Skip to content

Commit

Permalink
Merge pull request #348 from V02460/json_string
Browse files Browse the repository at this point in the history
Encode \b and \f in JSON string as themselves
  • Loading branch information
tidwall authored Feb 15, 2024
2 parents 6ee9f87 + 0f87896 commit 711c6fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
1 change: 1 addition & 0 deletions gjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 711c6fe

Please sign in to comment.