File tree Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Original file line number Diff line number Diff line change @@ -95,13 +95,7 @@ module.exports = class Serializer {
95
95
96
96
if ( len === 0 ) {
97
97
return '""'
98
- }
99
-
100
- if ( ! str . isWellFormed ( ) ) {
101
- return JSON . stringify ( str )
102
- }
103
-
104
- if ( len < 42 ) {
98
+ } else if ( len < 42 ) {
105
99
// magically escape strings for json
106
100
// relying on their charCodeAt
107
101
// everything below 32 needs JSON.stringify()
@@ -120,13 +114,13 @@ module.exports = class Serializer {
120
114
last === - 1 && ( last = 0 )
121
115
result += str . slice ( last , i ) + '\\'
122
116
last = i
123
- } else if ( point < 32 ) {
117
+ } else if ( point < 32 || ( point >= 0xd800 && point <= 0xdfff ) ) {
124
118
// The current character is non-printable characters or a surrogate.
125
119
return JSON . stringify ( str )
126
120
}
127
121
}
128
122
return ( last === - 1 && ( '"' + str + '"' ) ) || ( '"' + result + str . slice ( last ) + '"' )
129
- } else if ( len < 5000 && ASCII_ESCAPE . test ( str ) === false ) {
123
+ } else if ( len < 5000 && str . isWellFormed ( ) && ASCII_ESCAPE . test ( str ) === false ) {
130
124
// Only use the regular expression for shorter input. The overhead is otherwise too much.
131
125
return '"' + str + '"'
132
126
} else {
You can’t perform that action at this time.
0 commit comments