Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Fix broken expectation in Safari for serializing invalid dates. #14221

Closed
wants to merge 8 commits into from
2 changes: 2 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down