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

Commit 693e846

Browse files
SekibOmaziccaitp
authored andcommitted
fix(Angular): make Date comparison in equals() NaN-aware
Make angular.equals() Date comparison NaN-aware to prevent infinite digest errors when a dealy watched date has an invalid value. Closes #8650 Closes #8715
1 parent fdeaa74 commit 693e846

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Angular.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ function equals(o1, o2) {
895895
return true;
896896
}
897897
} else if (isDate(o1)) {
898-
return isDate(o2) && o1.getTime() == o2.getTime();
898+
if (!isDate(o2)) return false;
899+
return (isNaN(o1.getTime()) && isNaN(o2.getTime())) || (o1.getTime() === o2.getTime());
899900
} else if (isRegExp(o1) && isRegExp(o2)) {
900901
return o1.toString() == o2.toString();
901902
} else {

test/AngularSpec.js

+5
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ describe('angular', function() {
362362
expect(equals(new Date(0), new Date(1))).toBe(false);
363363
expect(equals(new Date(0), 0)).toBe(false);
364364
expect(equals(0, new Date(0))).toBe(false);
365+
366+
expect(equals(new Date(undefined), new Date(undefined))).toBe(true);
367+
expect(equals(new Date(undefined), new Date(0))).toBe(false);
368+
expect(equals(new Date(undefined), new Date(null))).toBe(false);
369+
expect(equals(new Date(undefined), new Date('wrong'))).toBe(true);
365370
});
366371

367372
it('should correctly test for keys that are present on Object.prototype', function() {

0 commit comments

Comments
 (0)