Skip to content

Commit b204006

Browse files
TooTallNatebnoordhuis
authored andcommitted
util: ensure that the .inspect function isn't the one being executed
Fixes #2225.
1 parent 754e23d commit b204006

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function formatValue(ctx, value, recurseTimes) {
155155
// Check that value is an object with an inspect function on it
156156
if (value && typeof value.inspect === 'function' &&
157157
// Filter out the util module, it's inspect function is special
158-
value !== exports &&
158+
value.inspect !== exports.inspect &&
159159
// Also filter out any prototype objects using the circular check.
160160
!(value.constructor && value.constructor.prototype === value)) {
161161
return value.inspect(recurseTimes);

test/simple/test-util-inspect.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@ assert.doesNotThrow(function () {
7575
r.toString = null;
7676
util.inspect(r);
7777
});
78+
79+
// GH-2225
80+
var x = { inspect: util.inspect };
81+
assert.ok(util.inspect(x).indexOf('inspect') != -1);

0 commit comments

Comments
 (0)