summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/internal/util/inspect.js43
-rw-r--r--test/parallel/test-fs-whatwg-url.js6
-rw-r--r--test/parallel/test-util-inspect.js7
3 files changed, 31 insertions, 25 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 {
diff --git a/test/parallel/test-fs-whatwg-url.js b/test/parallel/test-fs-whatwg-url.js
index c5f4d81dfb..377f6d010c 100644
--- a/test/parallel/test-fs-whatwg-url.js
+++ b/test/parallel/test-fs-whatwg-url.js
@@ -63,7 +63,7 @@ if (common.isWindows) {
code: 'ERR_INVALID_ARG_VALUE',
type: TypeError,
message: 'The argument \'path\' must be a string or Uint8Array without ' +
- 'null bytes. Received \'c:\\\\tmp\\\\\\u0000test\''
+ "null bytes. Received 'c:\\\\tmp\\\\\\x00test'"
}
);
} else {
@@ -96,8 +96,8 @@ if (common.isWindows) {
{
code: 'ERR_INVALID_ARG_VALUE',
type: TypeError,
- message: 'The argument \'path\' must be a string or Uint8Array without ' +
- 'null bytes. Received \'/tmp/\\u0000test\''
+ message: "The argument 'path' must be a string or Uint8Array without " +
+ "null bytes. Received '/tmp/\\x00test'"
}
);
}
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index e7804eec2f..b48bb56736 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -91,10 +91,11 @@ assert.strictEqual(
new Date('2010-02-14T12:48:40+01:00').toISOString()
);
assert.strictEqual(util.inspect(new Date('')), (new Date('')).toString());
-assert.strictEqual(util.inspect('\n\u0001'), "'\\n\\u0001'");
+assert.strictEqual(util.inspect('\n\x01'), "'\\n\\x01'");
assert.strictEqual(
- util.inspect(`${Array(75).fill(1)}'\n\u001d\n\u0003`),
- `"${Array(75).fill(1)}'\\n" +\n '\\u001d\\n' +\n '\\u0003'`
+ util.inspect(`${Array(75).fill(1)}'\n\x1d\n\x03\x85\x7f\x7e\x9f\xa0`),
+ // eslint-disable-next-line no-irregular-whitespace
+ `"${Array(75).fill(1)}'\\n" +\n '\\x1D\\n' +\n '\\x03\\x85\\x7F~\\x9F '`
);
assert.strictEqual(util.inspect([]), '[]');
assert.strictEqual(util.inspect(Object.create([])), 'Array {}');