Skip to content

Commit

Permalink
util: inspect: do not crash on an Error with a regex name
Browse files Browse the repository at this point in the history
See #56570
  • Loading branch information
ljharb committed Jan 12, 2025
1 parent 4c27393 commit d33853a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ function removeDuplicateErrorKeys(ctx, keys, err, stack) {
for (const name of ['name', 'message', 'stack']) {
const index = ArrayPrototypeIndexOf(keys, name);
// Only hide the property in case it's part of the original stack
if (index !== -1 && StringPrototypeIncludes(stack, err[name])) {
if (index !== -1 && StringPrototypeIncludes(stack, String(err[name]))) {
ArrayPrototypeSplice(keys, index, 1);
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3426,3 +3426,14 @@ assert.strictEqual(
Object.defineProperty(BuiltinPrototype, 'constructor', desc);
}
}

{
const error = new Error();
const re = /a/g;
error.name = re;
assert.strictEqual(error.name, re);
assert.strictEqual(
util.inspect(error),
error.stack,
);
}

0 comments on commit d33853a

Please sign in to comment.