Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
util: handle non-string return value in .inspect()
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka authored and bnoordhuis committed May 9, 2012
1 parent 7d2e68f commit e859271
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util.js
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/simple/test-util-inspect.js
Expand Up @@ -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.