summaryrefslogtreecommitdiff
path: root/test/parallel/test-util-inspect.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-07-02 20:52:34 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-07-16 14:18:25 +0200
commitb3e93a91eb4e2c38c07550d61be899bd32137a0a (patch)
tree0ea0125536f18d7a41ce8c0d0594dde0306ead7e /test/parallel/test-util-inspect.js
parent49681e7414629e0d3fbc3ac5bfbd3fa46725c49c (diff)
downloadandroid-node-v8-b3e93a91eb4e2c38c07550d61be899bd32137a0a.tar.gz
android-node-v8-b3e93a91eb4e2c38c07550d61be899bd32137a0a.tar.bz2
android-node-v8-b3e93a91eb4e2c38c07550d61be899bd32137a0a.zip
util: do not escape single quotes if not necessary
Right now util.inspect will always escape single quotes. That is not necessary though in case the string that will be escaped does not contain double quotes. In that case the string can simply be wrapped in double quotes instead. If the string contains single and double quotes and it does not contain `${` as part of the string, backticks will be used instead. That makes sure only very few strings have to escape quotes at all. Thus it increases the readability of these strings. PR-URL: https://github.com/nodejs/node/pull/21624 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-util-inspect.js')
-rw-r--r--test/parallel/test-util-inspect.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index f97ab95cde..e0dceb60f7 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -47,7 +47,7 @@ assert.strictEqual(util.inspect(new Date('')), (new Date('')).toString());
assert.strictEqual(util.inspect('\n\u0001'), "'\\n\\u0001'");
assert.strictEqual(
util.inspect(`${Array(75).fill(1)}'\n\u001d\n\u0003`),
- `'${Array(75).fill(1)}\\'\\n\\u001d\\n\\u0003'`
+ `"${Array(75).fill(1)}'\\n\\u001d\\n\\u0003"`
);
assert.strictEqual(util.inspect([]), '[]');
assert.strictEqual(util.inspect(Object.create([])), 'Array {}');
@@ -1424,3 +1424,9 @@ util.inspect(process);
assert(longList.includes('[Object: Inspection interrupted ' +
'prematurely. Maximum call stack size exceeded.]'));
}
+
+// Do not escape single quotes if no double quote or backtick is present.
+assert.strictEqual(util.inspect("'"), '"\'"');
+assert.strictEqual(util.inspect('"\''), '`"\'`');
+// eslint-disable-next-line no-template-curly-in-string
+assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");