diff --git a/lib/utils/common.js b/lib/utils/common.js index 89be16e..fe6770f 100644 --- a/lib/utils/common.js +++ b/lib/utils/common.js @@ -1,6 +1,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +const jsesc = require('jsesc') const utils = require('../utils') class common extends utils { @@ -30,28 +31,7 @@ class common extends utils { } static quote (s) { - // Taken from DOMfuzz - function escapeString (s) { - 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') { - 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|), just coerce to string. - return JSON.stringify(s) - } + return jsesc(s) } static b64encode (str) {