Skip to content

Commit 7b84363

Browse files
barinalievanlucas
authored andcommitted
util: fix inspecting symbol key in string
PR-URL: #11672 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8402888 commit 7b84363

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ function formatValue(ctx, value, recurseTimes) {
396396
// for boxed Strings, we have to remove the 0-n indexed entries,
397397
// since they just noisy up the output and are redundant
398398
keys = keys.filter(function(key) {
399+
if (typeof key === 'symbol') {
400+
return true;
401+
}
402+
399403
return !(key >= 0 && key < raw.length);
400404
});
401405
}

test/parallel/test-util-inspect.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ assert.strictEqual(util.inspect(Object.create({},
5050
{visible: {value: 1, enumerable: true}, hidden: {value: 2}})),
5151
'{ visible: 1 }'
5252
);
53+
assert.strictEqual(util.inspect(Object.assign(new String('hello'),
54+
{ [Symbol('foo')]: 123 }), { showHidden: true }),
55+
'{ [String: \'hello\'] [length]: 5, [Symbol(foo)]: 123 }');
5356

5457
{
5558
const regexp = /regexp/;

0 commit comments

Comments
 (0)