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
This commit is contained in:
Sekib Omazic
2014-08-22 01:40:36 +02:00
committed by Caitlin Potter
parent ebece0bcb9
commit 98f603722d
2 changed files with 7 additions and 1 deletions

View File

@@ -911,7 +911,8 @@ function equals(o1, o2) {
return true;
}
} else if (isDate(o1)) {
return isDate(o2) && o1.getTime() == o2.getTime();
if (!isDate(o2)) return false;
return (isNaN(o1.getTime()) && isNaN(o2.getTime())) || (o1.getTime() === o2.getTime());
} else if (isRegExp(o1) && isRegExp(o2)) {
return o1.toString() == o2.toString();
} else {

View File

@@ -366,6 +366,11 @@ describe('angular', function() {
expect(equals(new Date(0), new Date(1))).toBe(false);
expect(equals(new Date(0), 0)).toBe(false);
expect(equals(0, new Date(0))).toBe(false);
expect(equals(new Date(undefined), new Date(undefined))).toBe(true);
expect(equals(new Date(undefined), new Date(0))).toBe(false);
expect(equals(new Date(undefined), new Date(null))).toBe(false);
expect(equals(new Date(undefined), new Date('wrong'))).toBe(true);
});
it('should correctly test for keys that are present on Object.prototype', function() {