From 525506b5ed9f8228f2a4d112202137d5419b66a6 Mon Sep 17 00:00:00 2001 From: Gonzalo Ruiz de Villa Date: Tue, 11 Dec 2012 20:37:05 +0100 Subject: [PATCH] fix(equals): correctly compare objects with undefined member variables given a = {} and b = {x:undefined} then angular.equals(a, b) should be true angular.equals(b, a) should be true (this happened before) Signed-off-by: Gonzalo Ruiz de Villa --- src/Angular.js | 8 +++++++- test/AngularSpec.js | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Angular.js b/src/Angular.js index 3a11f3ea7188..54967be83762 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -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; } diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 476702968ec1..d47e1d3b729d 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -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);