Skip to content

Commit

Permalink
Fix apollo-utilities isEqual bug due to missing hasOwnProperty check. (
Browse files Browse the repository at this point in the history
  • Loading branch information
samkline authored and benjamn committed Oct 29, 2018
1 parent 42dd7f8 commit 4ef4633
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/apollo-utilities/src/util/__tests__/isEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,11 @@ describe('isEqual', () => {
);
expect(!isEqual(objNoProto, null)).toBe(true);
});

it('should correctly handle modified prototypes', () => {
Array.prototype.foo = null;
expect(isEqual([1, 2, 3], [1, 2, 3])).toBe(true);
expect(!isEqual([1, 2, 3], [1, 2, 4])).toBe(true);
delete Array.prototype.foo;
});
});
5 changes: 4 additions & 1 deletion packages/apollo-utilities/src/util/isEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export function isEqual(a: any, b: any): boolean {
}
// Look through all the keys in `b`. If `b` has a key that `a` does not, return false.
for (const key in b) {
if (!Object.prototype.hasOwnProperty.call(a, key)) {
if (
Object.prototype.hasOwnProperty.call(b, key) &&
!Object.prototype.hasOwnProperty.call(a, key)
) {
return false;
}
}
Expand Down

0 comments on commit 4ef4633

Please sign in to comment.