Skip to content

Commit

Permalink
util: fix inspecting symbol key in string
Browse files Browse the repository at this point in the history
PR-URL: nodejs#11672
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
barinali committed May 7, 2017
1 parent 312091a commit 5422cf5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ function formatValue(ctx, value, recurseTimes) {
// for boxed Strings, we have to remove the 0-n indexed entries,
// since they just noisy up the output and are redundant
keys = keys.filter(function(key) {
if (typeof key === 'symbol') {
return true;
}

return !(key >= 0 && key < raw.length);
});
}
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ assert.strictEqual(util.inspect(Object.create({},
{visible: {value: 1, enumerable: true}, hidden: {value: 2}})),
'{ visible: 1 }'
);
assert.strictEqual(util.inspect(Object.assign(new String('hello'),
{ [Symbol('foo')]: 123 }), { showHidden: true }),
'{ [String: \'hello\'] [length]: 5, [Symbol(foo)]: 123 }');

{
const regexp = /regexp/;
Expand Down

0 comments on commit 5422cf5

Please sign in to comment.