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

Commit

Permalink
fix(Angular): make Date comparison in equals() NaN-aware
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SekibOmazic authored and caitp committed Aug 22, 2014
1 parent fdeaa74 commit 693e846
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,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 {
Expand Down
5 changes: 5 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,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() {
Expand Down

0 comments on commit 693e846

Please sign in to comment.