diff --git a/lib/tools.js b/lib/tools.js index 92bd23ba6..3bb74ee04 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -73,6 +73,9 @@ function genLog (level, hook) { } } +// eslint-disable-next-line +const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/ + // magically escape strings for json // relying on their charCodeAt // everything below 32 needs JSON.stringify() @@ -84,6 +87,9 @@ function asString (str) { let found = false let point = 255 const l = str.length + if (!STR_ESCAPE.test(str)) { + return '"' + str + '"' + } if (l > 100) { return JSON.stringify(str) }