mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
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:
committed by
Caitlin Potter
parent
ebece0bcb9
commit
98f603722d
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user