Skip to content

Commit 444a514

Browse files
committed
Fix exceptions on sub-objects (reformat pull request from @Robinfr). Closes cdinger#2.
1 parent b763928 commit 444a514

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

jquery.objectdiff.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
c[prop] = $.objectDiff(a[prop], b[prop], c);
3131
}
3232
else {
33+
if(a === undefined) a = {};
34+
if(b === undefined) b = {};
3335
if (a[prop] !== b[prop]) {
3436
c[prop] = [a[prop], b[prop]];
3537
}

spec/objectdiff_spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,12 @@ describe("objectDiff", function() {
3434
var diff = {};
3535
expect($.objectDiff(before, after)).toEqual(diff);
3636
});
37-
});
3837

38+
// Github issue #2
39+
it("should not throw exception when encountering sub-objects", function() {
40+
var a = { x: { i:1, j:2, k: 3 }};
41+
var b = { x: { i:2, j:2, k: 3 }, y: { i:2 }};
42+
var diff = {x:{i:[1,2]}, y:{i:[undefined,2]}};
43+
expect($.objectDiff(a, b)).toEqual(diff);
44+
});
45+
});

0 commit comments

Comments
 (0)