From 742401a0e1fc7a1c20d1687f16ffb205178e11bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrg=20Lehni?= <juerg@scratchdisk.com>
Date: Mon, 13 Jun 2016 14:16:25 +0200
Subject: [PATCH] Fix Item#insertChildren() error when passing null for some
 children.

Relates to #1036
---
 src/item/Item.js    |  2 +-
 test/tests/Group.js | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/item/Item.js b/src/item/Item.js
index 1b3f5d0a..112d737c 100644
--- a/src/item/Item.js
+++ b/src/item/Item.js
@@ -2353,7 +2353,7 @@ new function() { // Injection scope for hit-test functions shared with project
             // Use the loop also to filter out wrong _type.
             for (var i = items.length - 1; i >= 0; i--) {
                 var item = items[i];
-                if (_proto && !(item instanceof _proto)) {
+                if (!item || _proto && !(item instanceof _proto)) {
                     items.splice(i, 1);
                 } else {
                     // Notify parent of change. Don't notify item itself yet,
diff --git a/test/tests/Group.js b/test/tests/Group.js
index fdc72e6a..3c67df44 100644
--- a/test/tests/Group.js
+++ b/test/tests/Group.js
@@ -108,3 +108,21 @@ test('group.insertChildren(0, otherGroup.children)', function() {
         return group.children.length;
     }, 0);
 });
+
+test('group.addChildren()', function() {
+    var group = new Group();
+    var children = [new Path(), new Path()];
+    group.addChildren(children);
+    equals(group.children.length, 2,
+            'group.children.length after adding 2 children');
+    group.removeChildren();
+    equals(group.children.length, 0,
+            'group.children.length after removing all children');
+    children.splice(1, 0, null);
+    equals(children.length, 3,
+            'children array length after inserting null at index 1');
+    group.addChildren(children);
+    equals(group.children.length, 2,
+            'calling group.addChildren() with an array with 3 entries, ' +
+            'of which 2 are valid, group.children.length should be 2');
+});