summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-10-03 03:41:38 +0200
committerAnna Henningsen <anna@addaleax.net>2019-11-19 13:34:40 +0100
commit0f78dcc86d9af8f742f76505c5a104c6dff17ca9 (patch)
treeb7dd0eb43fc0dfa1ce73b8e753ebfd30b34a9d12 /lib
parent5e4d99ae6e3b32b8c30404f77c33fa9cfc5ca22d (diff)
downloadandroid-node-v8-0f78dcc86d9af8f742f76505c5a104c6dff17ca9.tar.gz
android-node-v8-0f78dcc86d9af8f742f76505c5a104c6dff17ca9.tar.bz2
android-node-v8-0f78dcc86d9af8f742f76505c5a104c6dff17ca9.zip
util: escape C1 control characters and switch to hex format
C1 control characters will from now on also be escaped to prevent altering the terminal behavior. Fixes: https://github.com/nodejs/node/issues/29450 PR-URL: https://github.com/nodejs/node/pull/29826 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/util/inspect.js43
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 2f922f6659..cc7f23f321 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -115,10 +115,10 @@ const kArrayType = 1;
const kArrayExtrasType = 2;
/* eslint-disable no-control-regex */
-const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c]/;
-const strEscapeSequencesReplacer = /[\x00-\x1f\x27\x5c]/g;
-const strEscapeSequencesRegExpSingle = /[\x00-\x1f\x5c]/;
-const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c]/g;
+const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c\x7f-\x9f]/;
+const strEscapeSequencesReplacer = /[\x00-\x1f\x27\x5c\x7f-\x9f]/g;
+const strEscapeSequencesRegExpSingle = /[\x00-\x1f\x5c\x7f-\x9f]/;
+const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]/g;
/* eslint-enable no-control-regex */
const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
@@ -134,21 +134,23 @@ const kWeak = 0;
const kIterator = 1;
const kMapEntries = 2;
-// Escaped special characters. Use empty strings to fill up unused entries.
+// Escaped control characters (plus the single quote and the backslash). Use
+// empty strings to fill up unused entries.
const meta = [
- '\\u0000', '\\u0001', '\\u0002', '\\u0003', '\\u0004',
- '\\u0005', '\\u0006', '\\u0007', '\\b', '\\t',
- '\\n', '\\u000b', '\\f', '\\r', '\\u000e',
- '\\u000f', '\\u0010', '\\u0011', '\\u0012', '\\u0013',
- '\\u0014', '\\u0015', '\\u0016', '\\u0017', '\\u0018',
- '\\u0019', '\\u001a', '\\u001b', '\\u001c', '\\u001d',
- '\\u001e', '\\u001f', '', '', '',
- '', '', '', '', "\\'", '', '', '', '', '',
- '', '', '', '', '', '', '', '', '', '',
- '', '', '', '', '', '', '', '', '', '',
- '', '', '', '', '', '', '', '', '', '',
- '', '', '', '', '', '', '', '', '', '',
- '', '', '', '', '', '', '', '\\\\'
+ '\\x00', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\x07', // x07
+ '\\b', '\\t', '\\n', '\\x0B', '\\f', '\\r', '\\x0E', '\\x0F', // x0F
+ '\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17', // x17
+ '\\x18', '\\x19', '\\x1A', '\\x1B', '\\x1C', '\\x1D', '\\x1E', '\\x1F', // x1F
+ '', '', '', '', '', '', '', "\\'", '', '', '', '', '', '', '', '', // x2F
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x3F
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x4F
+ '', '', '', '', '', '', '', '', '', '', '', '', '\\\\', '', '', '', // x5F
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x6F
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\\x7F', // x7F
+ '\\x80', '\\x81', '\\x82', '\\x83', '\\x84', '\\x85', '\\x86', '\\x87', // x87
+ '\\x88', '\\x89', '\\x8A', '\\x8B', '\\x8C', '\\x8D', '\\x8E', '\\x8F', // x8F
+ '\\x90', '\\x91', '\\x92', '\\x93', '\\x94', '\\x95', '\\x96', '\\x97', // x97
+ '\\x98', '\\x99', '\\x9A', '\\x9B', '\\x9C', '\\x9D', '\\x9E', '\\x9F', // x9F
];
function getUserOptions(ctx) {
@@ -317,7 +319,10 @@ function strEscape(str) {
const lastIndex = str.length;
for (let i = 0; i < lastIndex; i++) {
const point = str.charCodeAt(i);
- if (point === singleQuote || point === 92 || point < 32) {
+ if (point === singleQuote ||
+ point === 92 ||
+ point < 32 ||
+ (point > 126 && point < 160)) {
if (last === i) {
result += meta[point];
} else {