From 5ae63fd385295d5a7bbdc79466f59727dcab1c85 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 17 Jan 2013 16:53:30 -0800 Subject: fix(angular.equals): consistently compare undefined object props previously: a = {}; b = {x:undefined}; angular.equals(a, b) == angular.equals(b, a) // returns false. both should return false because these objects are not equal. unlike in implemented in #1695 the comparison should be stricter and return false not true. if we need to relax this in the future we can always do so. Closes #1648 --- src/Angular.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/Angular.js') diff --git a/src/Angular.js b/src/Angular.js index 3a11f3ea..21b3ef07 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -620,16 +620,23 @@ function equals(o1, o2) { } else { if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2)) return false; keySet = {}; + length = 0; for(key in o1) { - if (key.charAt(0) !== '$' && !isFunction(o1[key]) && !equals(o1[key], o2[key])) { - return false; - } + if (key.charAt(0) === '$') continue; + + if (!isFunction(o1[key]) && !equals(o1[key], o2[key])) return false; + + length++; keySet[key] = true; } for(key in o2) { - if (!keySet[key] && key.charAt(0) !== '$' && !isFunction(o2[key])) return false; + if (key.charAt(0) === '$') { + continue; + } + if (!keySet[key] && !isFunction(o2[key])) return false; + length--; } - return true; + return length === 0; } } } -- cgit v1.2.3