diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 59219821230b51..74cca85996d5c2 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 8314b64c5ac345..f70090f48939d7 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -3095,3 +3095,10 @@ assert.strictEqual( ']' ); } + +{ + assert.strictEqual( + util.inspect({ ['__proto__']: { a: 1 } }), + "{ ['__proto__']: { a: 1 } }" + ); +}