Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

util: handle non-string return value in .inspect()

  • Loading branch information...
rlidwka authored and bnoordhuis committed May 6, 2012
1 parent 7d2e68f commit e85927119cd76dfa6541beb7954196c56d98a776
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/util.js
  2. +7 −0 test/simple/test-util-inspect.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
@@ -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);

0 comments on commit e859271

Please sign in to comment.
You can’t perform that action at this time.