Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
util: inspect __proto__ key as written in object literal
Since util.inspect() gives object-literal-like output, handle the
special `__proto__` key in the way that it would be handled in object
literals.
  • Loading branch information
addaleax committed Mar 11, 2021
commit 8a8f5d8f58c6629902285a1585b1838f1eeea1db
2 changes: 2 additions & 0 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,8 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
strEscapeSequencesReplacer, escapeFn
);
name = `[${ctx.stylize(tmp, 'symbol')}]`;
} else if (key === '__proto__') {
name = "['__proto__']";
} else if (desc.enumerable === false) {
const tmp = StringPrototypeReplace(key,
strEscapeSequencesReplacer, escapeFn);
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3095,3 +3095,10 @@ assert.strictEqual(
']'
);
}

{
assert.strictEqual(
util.inspect({ ['__proto__']: { a: 1 } }),
"{ ['__proto__']: { a: 1 } }"
);
}