Skip to content

Commit

Permalink
Merge pull request #1661 from a8m/fix-issue-1660
Browse files Browse the repository at this point in the history
fix(utils/stringify): fix issue #1660
  • Loading branch information
boneskull committed Apr 18, 2015
2 parents f9fad1b + ac13adf commit ab1a418
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ function jsonStringify(object, spaces, depth) {
: val.toString();
break;
case 'date':
val = '[Date: ' + val.toISOString() + ']';
var sDate = isNaN(val.getTime()) // Invalid date
? val.toString()
: val.toISOString();
val = '[Date: ' + sDate + ']';
break;
case 'buffer':
var json = val.toJSON();
Expand Down
4 changes: 4 additions & 0 deletions test/acceptance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ describe('lib/utils', function () {
stringify(date).should.equal('[Date: ' + date.toISOString() + ']');
});

it('should return invalid Date object with .toString() + string prefix', function() {
stringify(new Date('')).should.equal('[Date: ' + new Date('').toString() + ']');
});

describe('#Number', function() {
it('should show the handle -0 situations', function() {
stringify(-0).should.eql('-0');
Expand Down

0 comments on commit ab1a418

Please sign in to comment.