Skip to content

Commit 1f2a8f0

Browse files
committed
util: inspect: do not crash on an Error stack with a regex name
See #56570
1 parent 4c27393 commit 1f2a8f0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/internal/util/inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ function removeDuplicateErrorKeys(ctx, keys, err, stack) {
13541354
for (const name of ['name', 'message', 'stack']) {
13551355
const index = ArrayPrototypeIndexOf(keys, name);
13561356
// Only hide the property in case it's part of the original stack
1357-
if (index !== -1 && StringPrototypeIncludes(stack, err[name])) {
1357+
if (index !== -1 && StringPrototypeIncludes(stack, String(err[name]))) {
13581358
ArrayPrototypeSplice(keys, index, 1);
13591359
}
13601360
}

test/parallel/test-util-inspect.js

+11
Original file line numberDiff line numberDiff line change
@@ -3426,3 +3426,14 @@ assert.strictEqual(
34263426
Object.defineProperty(BuiltinPrototype, 'constructor', desc);
34273427
}
34283428
}
3429+
3430+
{
3431+
const error = new Error();
3432+
const re = /a/g;
3433+
error.name = re;
3434+
assert.strictEqual(error.name, re);
3435+
assert.strictEqual(
3436+
util.inspect(error),
3437+
error.stack,
3438+
);
3439+
}

0 commit comments

Comments
 (0)