Skip to content

Commit

Permalink
fix(Angular): Infinite $digest Loop occur when using deep $watch on a…
Browse files Browse the repository at this point in the history
…n object that contains an "Invalid Date"

Add better check for invalid dates in method equals.

fixes angular#8650
  • Loading branch information
SekibOmazic committed Aug 21, 2014
1 parent dfbe69c commit 19f0517
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 19f0517

Please sign in to comment.