diff --git a/src/Angular.js b/src/Angular.js index c3e326d756fe..630b90df40fe 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1169,6 +1169,8 @@ function toJsonReplacer(key, value) { val = '$DOCUMENT'; } else if (isScope(value)) { val = '$SCOPE'; + } else if (isDate(value) && isNaN(value.getMilliseconds())) { + val = null; } return val; diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 314ff17c0119..6babe2360e44 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -2058,6 +2058,10 @@ describe('angular', function() { it('should serialize undefined as undefined', function() { expect(toJson(undefined)).toEqual(undefined); }); + + it('should serialize invalid dates to null', function() { + expect(toJson({when: new Date(1 / 0)})).toEqual('{"when":null}'); + }); }); describe('isElement', function() {