diff --git a/src/engine/adapter.js b/src/engine/adapter.js
index 7f891da34..48613ec5d 100644
--- a/src/engine/adapter.js
+++ b/src/engine/adapter.js
@@ -32,6 +32,9 @@ function domToBlocks (blocksDOM) {
var blocks = {};
for (var i = 0; i < blocksDOM.length; i++) {
var block = blocksDOM[i];
+ if (!block.name || !block.attribs) {
+ continue;
+ }
var tagName = block.name.toLowerCase();
if (tagName == 'block' || tagName == 'shadow') {
domToBlock(block, blocks, true);
@@ -114,6 +117,10 @@ function domToBlock (blockDOM, blocks, isTopBlock) {
};
break;
case 'next':
+ if (!childBlockNode || !childBlockNode.attribs) {
+ // Invalid child block.
+ continue;
+ }
// Recursively generate block structure for next block.
domToBlock(childBlockNode, blocks, false);
// Link next block to this block.
diff --git a/test/fixtures/events.json b/test/fixtures/events.json
index f6f4cb796..6d94fc62a 100644
--- a/test/fixtures/events.json
+++ b/test/fixtures/events.json
@@ -35,5 +35,23 @@
"xml": {
"outerHTML": ""
}
+ },
+ "createinvalid": {
+ "name": "whatever",
+ "xml": {
+ "outerHTML": ""
+ }
+ },
+ "createinvalidgrandchild": {
+ "name": "block",
+ "xml": {
+ "outerHTML": "xxx"
+ }
+ },
+ "createbadxml": {
+ "name": "whatever",
+ "xml": {
+ "outerHTML": ">"
+ }
}
}
diff --git a/test/unit/adapter.js b/test/unit/adapter.js
index 72be10d88..838815626 100644
--- a/test/unit/adapter.js
+++ b/test/unit/adapter.js
@@ -141,3 +141,27 @@ test('create with next connection', function (t) {
t.end();
});
+
+test('create with invalid block xml', function (t) {
+ // Entirely invalid block XML
+ var result = adapter(events.createinvalid);
+ t.ok(Array.isArray(result));
+ t.equal(result.length, 0);
+
+ // Invalid grandchild tag
+ var result2 = adapter(events.createinvalidgrandchild);
+ t.ok(Array.isArray(result2));
+ t.equal(result2.length, 1);
+ t.type(result2[0].id, 'string');
+ t.equal(Object.keys(result2[0].inputs).length, 0);
+ t.equal(Object.keys(result2[0].fields).length, 0);
+
+ t.end();
+});
+
+test('create with invalid xml', function (t) {
+ var result = adapter(events.createbadxml);
+ t.ok(Array.isArray(result));
+ t.equal(result.length, 0);
+ t.end();
+});