aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2011-01-13 07:55:31 -0800
committerIgor Minar2011-01-13 07:55:31 -0800
commitb0be87f663e8684c1369e1bff740c1750ba17080 (patch)
tree8faf8ffdcc6654499e6a1a5851e9a3f6bac062d4
parent9ccd2f0412ff97cdcb5c37fa3b75fea027d4e925 (diff)
downloadangular.js-b0be87f663e8684c1369e1bff740c1750ba17080.tar.bz2
fix for angular.Object.equals to handle equals({},null)
-rw-r--r--src/Angular.js1
-rw-r--r--test/AngularSpec.js22
2 files changed, 23 insertions, 0 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 00e1d2a2..762291ef 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -631,6 +631,7 @@ function copy(source, destination){
*/
function equals(o1, o2) {
if (o1 == o2) return true;
+ if (o1 === null || o2 === null) return false;
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
if (t1 == t2 && t1 == 'object') {
if (o1 instanceof Array) {
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index 62298465..0e6b2bfa 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -89,6 +89,28 @@ describe('equals', function(){
it('should ignore functions', function(){
expect(equals({func: function() {}}, {bar: function() {}})).toEqual(true);
});
+
+ it('should work well with nulls', function() {
+ expect(equals(null, '123')).toBe(false);
+ expect(equals('123', null)).toBe(false);
+
+ var obj = {foo:'bar'};
+ expect(equals(null, obj)).toBe(false);
+ expect(equals(obj, null)).toBe(false);
+
+ expect(equals(null, null)).toBe(true);
+ });
+
+ it('should work well with undefined', function() {
+ expect(equals(undefined, '123')).toBe(false);
+ expect(equals('123', undefined)).toBe(false);
+
+ var obj = {foo:'bar'};
+ expect(equals(undefined, obj)).toBe(false);
+ expect(equals(obj, undefined)).toBe(false);
+
+ expect(equals(undefined, undefined)).toBe(true);
+ });
});
describe('parseKeyValue', function() {