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

Commit 98f6037

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 ebece0b commit 98f6037

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
@@ -911,7 +911,8 @@ function equals(o1, o2) {
911911
return true;
912912
}
913913
} else if (isDate(o1)) {
914-
return isDate(o2) && o1.getTime() == o2.getTime();
914+
if (!isDate(o2)) return false;
915+
return (isNaN(o1.getTime()) && isNaN(o2.getTime())) || (o1.getTime() === o2.getTime());
915916
} else if (isRegExp(o1) && isRegExp(o2)) {
916917
return o1.toString() == o2.toString();
917918
} else {

test/AngularSpec.js

+5
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ describe('angular', function() {
366366
expect(equals(new Date(0), new Date(1))).toBe(false);
367367
expect(equals(new Date(0), 0)).toBe(false);
368368
expect(equals(0, new Date(0))).toBe(false);
369+
370+
expect(equals(new Date(undefined), new Date(undefined))).toBe(true);
371+
expect(equals(new Date(undefined), new Date(0))).toBe(false);
372+
expect(equals(new Date(undefined), new Date(null))).toBe(false);
373+
expect(equals(new Date(undefined), new Date('wrong'))).toBe(true);
369374
});
370375

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

0 commit comments

Comments
 (0)