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