summaryrefslogtreecommitdiff
path: root/lib/internal/util/inspect.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/util/inspect.js')
-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 {