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

fix(equals): fix #1648 correctly compare objects with undefined member variables #1695

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,13 @@ function equals(o1, o2) {
keySet[key] = true;
}
for(key in o2) {
if (!keySet[key] && key.charAt(0) !== '$' && !isFunction(o2[key])) return false;
if (!keySet[key] &&
key.charAt(0) !== '$' &&
!isFunction(o2[key]) &&
!isUndefined(o2[key])
) {
return false;
}
}
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ describe('angular', function() {
expect(equals(['misko'], ['misko', 'adam'])).toEqual(false);
});

it('should ignore undefined member variables', function() {
expect(equals({name:'misko'}, {name:'misko', undefinedvar:undefined})).toEqual(true);
expect(equals({name:'misko', undefinedvar:undefined}, {name:'misko'})).toEqual(true);
});

it('should ignore $ member variables', function() {
expect(equals({name:'misko', $id:1}, {name:'misko', $id:2})).toEqual(true);
expect(equals({name:'misko'}, {name:'misko', $id:2})).toEqual(true);
Expand Down