aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrenton2013-06-01 23:29:18 -0700
committerBrian Ford2013-08-12 16:23:38 -0700
commitda1f7c762d36b646c107260f74daf3a0ab5f91f5 (patch)
tree1925943897cb2dcf7e64dc9e90b135adbd96108c
parent89366bdbf918175818cf03d6208ee6fd23db7d00 (diff)
downloadangular.js-da1f7c762d36b646c107260f74daf3a0ab5f91f5.tar.bz2
fix(equals): {} and [] should not be considered equivalent
angular.equals was returning inconsistent values for the comparison between {} and []: angular.equals({}, []) // true angular.equals([], {}]) // false Since these object are not of the same type, they should not be considered equivalent.
-rw-r--r--src/Angular.js3
-rw-r--r--test/AngularSpec.js5
2 files changed, 7 insertions, 1 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 8fd77096..362bc09b 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -665,6 +665,7 @@ function equals(o1, o2) {
if (t1 == t2) {
if (t1 == 'object') {
if (isArray(o1)) {
+ if (!isArray(o2)) return false;
if ((length = o1.length) == o2.length) {
for(key=0; key<length; key++) {
if (!equals(o1[key], o2[key])) return false;
@@ -676,7 +677,7 @@ function equals(o1, o2) {
} else if (isRegExp(o1) && isRegExp(o2)) {
return o1.toString() == o2.toString();
} else {
- if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2)) return false;
+ if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || isArray(o2)) return false;
keySet = {};
for(key in o1) {
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index 5da22174..5e7cb410 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -302,6 +302,11 @@ describe('angular', function() {
expect(equals(/^abc/, /abc/)).toBe(false);
expect(equals(/^abc/, '/^abc/')).toBe(false);
});
+
+ it('should return false when comparing an object and an array', function() {
+ expect(equals({}, [])).toBe(false);
+ expect(equals([], {})).toBe(false);
+ });
});
describe('size', function() {