Skip to content
Browse files

Preventing arrays from ending up with undefined values where the inde…

…x should have been deleted.
  • Loading branch information...
1 parent 08c0cb8 commit bcfe79eea4d34195b25a76378e70d1da290a692b @leinster leinster committed Mar 21, 2012
Showing with 7 additions and 2 deletions.
  1. +5 −1 src/jsondiffpatch.js
  2. +2 −1 test/test.js
View
6 src/jsondiffpatch.js
@@ -276,7 +276,11 @@
return;
}
if (typeof value == 'undefined') {
- delete obj[key];
+ if (obj instanceof Array) {
+ obj.splice(key, 1);
+ } else {
+ delete obj[key];
+ }
}
else {
obj[key] = value;
View
3 test/test.js
@@ -160,7 +160,7 @@ test("change from/to null", 1, function(){
equal(typeof this.delta2, "undefined", 'original equals new');
});
-test("change simple list", 1, function(){
+test("change simple list", 2, function(){
this.makeCopy();
@@ -171,6 +171,7 @@ test("change simple list", 1, function(){
this.diffPatch();
+ deepEqual(this.sa.languages, this.sa2.languages);
equal(typeof this.delta2, "undefined", 'original equals new');
});

0 comments on commit bcfe79e

Please sign in to comment.
Something went wrong with that request. Please try again.