From 53d9167682d8f3437d83073e5e5c3fa855825b1e Mon Sep 17 00:00:00 2001 From: Christoph Diehl <1614333+posidron@users.noreply.github.com> Date: Wed, 21 Mar 2018 22:04:57 +0100 Subject: [PATCH] Prefer jsesc for quoting --- lib/utils/common.js | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) 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) {