diff --git a/lib/serializer.js b/lib/serializer.js index 387e8927..f5830da8 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -128,10 +128,6 @@ module.exports = class Serializer { // eslint-disable-next-line for (var i = 0; i < len; i++) { point = str.charCodeAt(i) - if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) { - // The current character is non-printable characters or a surrogate. - return JSON.stringify(str) - } if ( point === 0x22 || // '"' point === 0x5c // '\' @@ -139,6 +135,9 @@ module.exports = class Serializer { last === -1 && (last = 0) result += str.slice(last, i) + '\\' last = i + } else if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) { + // The current character is non-printable characters or a surrogate. + return JSON.stringify(str) } }