From 0bb9953ddbdad9e950f3adb6fc8f5488a6c94090 Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 15 Jun 2017 17:24:32 -0400 Subject: [PATCH] Temporarily replace quote with jruderman's simpleSource --- lib/utils/common.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/utils/common.js b/lib/utils/common.js index 59dd7f7..57be6be 100644 --- a/lib/utils/common.js +++ b/lib/utils/common.js @@ -25,24 +25,28 @@ utils.common = { } return list }, - quote: function (obj) { + quote: function (s) { + // Taken from DOMfuzz function escapeString (s) { - let escaped = s.replace(/\\/g, '\\\\') - .replace(/\"/g, '\\\"') // eslint-disable-line no-useless-escape - .replace(/\0/g, '\\0') - .replace(/\n/g, '\\n') - .replace(/[^\0-~]/g, function (ch) { - return '\\u' + ('000' + ch.charCodeAt(0).toString(16)).slice(-4) - }) - - return '\"' + escaped + '\"' // eslint-disable-line no-useless-escape + return ('\"' + // eslint-disable-line no-useless-escape + s.replace(/\\/g, '\\\\') + .replace(/\"/g, '\\\"') // eslint-disable-line no-useless-escape + .replace(/\0/g, '\\0') + .replace(/\n/g, '\\n') + + '\"') // eslint-disable-line no-useless-escape } if (typeof s === 'string') { - return escapeString(obj) + if (/^[\n\x20-\x7f]*$/.exec(s) || !self.uneval) { // eslint-disable-line no-undef + // Printable ASCII characters and line breaks: try to make it pretty. + return escapeString(s) + } else { + // Non-ASCII: use uneval to get \u escapes. + return uneval(s) // eslint-disable-line no-undef + } } else { - // For other things (such as numbers, |null|, and |undefined|), stringify - return JSON.stringify(obj) + // For other things (such as numbers, |null|, and |undefined|), just coerce to string. + return JSON.stringify(s) } }, b64encode: function (str) {