diff --git a/lib/utils.js b/lib/utils.js index 3650a707cc..7e44edf28a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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(); diff --git a/test/acceptance/utils.js b/test/acceptance/utils.js index 6b373a45e3..e67250b6d1 100644 --- a/test/acceptance/utils.js +++ b/test/acceptance/utils.js @@ -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');