From e85927119cd76dfa6541beb7954196c56d98a776 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Sun, 6 May 2012 13:32:49 +0400 Subject: [PATCH] util: handle non-string return value in .inspect() --- lib/util.js | 2 +- test/simple/test-util-inspect.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index c7fcbccc8a9..ce6aff496a4 100644 --- a/lib/util.js +++ b/lib/util.js @@ -158,7 +158,7 @@ function formatValue(ctx, value, recurseTimes) { value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { - return value.inspect(recurseTimes); + return String(value.inspect(recurseTimes)); } // Primitive types cannot have properties diff --git a/test/simple/test-util-inspect.js b/test/simple/test-util-inspect.js index 942e6e6de45..5b8fed9ffff 100644 --- a/test/simple/test-util-inspect.js +++ b/test/simple/test-util-inspect.js @@ -97,6 +97,13 @@ assert.doesNotThrow(function() { util.inspect(r); }); +// bug with user-supplied inspect function returns non-string +assert.doesNotThrow(function() { + util.inspect([{ + inspect: function() { return 123; } + }]); +}); + // GH-2225 var x = { inspect: util.inspect }; assert.ok(util.inspect(x).indexOf('inspect') != -1);