From b204006105e556be07121abd52e5cf0da3d3d8ae Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 29 Nov 2011 18:21:10 -0800 Subject: [PATCH] util: ensure that the .inspect function isn't the one being executed Fixes #2225. --- lib/util.js | 2 +- test/simple/test-util-inspect.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index aafc0edf325..b00da2de9d0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -155,7 +155,7 @@ function formatValue(ctx, value, recurseTimes) { // Check that value is an object with an inspect function on it if (value && typeof value.inspect === 'function' && // Filter out the util module, it's inspect function is special - value !== exports && + value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { return value.inspect(recurseTimes); diff --git a/test/simple/test-util-inspect.js b/test/simple/test-util-inspect.js index 68fea328cc9..c7a64f63906 100644 --- a/test/simple/test-util-inspect.js +++ b/test/simple/test-util-inspect.js @@ -75,3 +75,7 @@ assert.doesNotThrow(function () { r.toString = null; util.inspect(r); }); + +// GH-2225 +var x = { inspect: util.inspect }; +assert.ok(util.inspect(x).indexOf('inspect') != -1);