File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ func ExpectedJSONSizeString(s string) int {
10
10
for _ , r := range s {
11
11
if r == '"' || r == '\\' {
12
12
out += 1
13
+ } else if r == '\b' || r == '\f' || r == '\n' || r == '\r' || r == '\t' {
14
+ // https://cs.opensource.google/go/go/+/master:src/encoding/json/encode.go;l=992-1001;drc=0909bcd9e4acb01089d588d608d669d69710e50a
15
+ out += 1
13
16
} else if r <= 0x1F {
14
17
// control codes \u0000 - \u001f
15
18
out += 5
Original file line number Diff line number Diff line change @@ -44,6 +44,21 @@ func TestExpectedJSONSizeString(t *testing.T) {
44
44
"control character DEL" : {
45
45
input : "\x7F " ,
46
46
},
47
+ "control character LF" : {
48
+ input : "\n " ,
49
+ },
50
+ "control character CR" : {
51
+ input : "\r " ,
52
+ },
53
+ "control character BS" : {
54
+ input : "\b " ,
55
+ },
56
+ "control character HT" : {
57
+ input : "\t " ,
58
+ },
59
+ "control character FF" : {
60
+ input : "\f " ,
61
+ },
47
62
"emoji" : {
48
63
input : "😮😗🧝🏾♀️" ,
49
64
},
You can’t perform that action at this time.
0 commit comments