diff --git a/nodes/core/core/80-function.js b/nodes/core/core/80-function.js index 224c1f8e2..dd0efe229 100644 --- a/nodes/core/core/80-function.js +++ b/nodes/core/core/80-function.js @@ -1,5 +1,5 @@ /** - * Copyright 2013,2015 IBM Corp. + * Copyright 2013, 2016 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,12 +30,16 @@ module.exports = function(RED) { if (msgs[m]) { if (util.isArray(msgs[m])) { for (var n=0; n < msgs[m].length; n++) { - msgs[m][n]._msgid = _msgid; - msgCount++; + if (msgs[m][n] !== null && msgs[m][n] !== undefined) { + msgs[m][n]._msgid = _msgid; + msgCount++; + } } } else { - msgs[m]._msgid = _msgid; - msgCount++; + if (msgs[m] !== null && msgs[m] !== undefined) { + msgs[m]._msgid = _msgid; + msgCount++; + } } } } diff --git a/red/runtime/nodes/Node.js b/red/runtime/nodes/Node.js index 8fe82d19c..3e936417e 100644 --- a/red/runtime/nodes/Node.js +++ b/red/runtime/nodes/Node.js @@ -157,16 +157,18 @@ Node.prototype.send = function(msg) { // for each msg to send eg. [[m1, m2, ...], ...] for (k = 0; k < msgs.length; k++) { var m = msgs[k]; - /* istanbul ignore else */ - if (!sentMessageId) { - sentMessageId = m._msgid; - } - if (msgSent) { - var clonedmsg = redUtil.cloneMessage(m); - sendEvents.push({n:node,m:clonedmsg}); - } else { - sendEvents.push({n:node,m:m}); - msgSent = true; + if (m !== null && m !== undefined) { + /* istanbul ignore else */ + if (!sentMessageId) { + sentMessageId = m._msgid; + } + if (msgSent) { + var clonedmsg = redUtil.cloneMessage(m); + sendEvents.push({n:node,m:clonedmsg}); + } else { + sendEvents.push({n:node,m:m}); + msgSent = true; + } } } } diff --git a/test/nodes/core/core/80-function_spec.js b/test/nodes/core/core/80-function_spec.js index e32f2bd6e..e94c2b76b 100644 --- a/test/nodes/core/core/80-function_spec.js +++ b/test/nodes/core/core/80-function_spec.js @@ -135,6 +135,30 @@ describe('function node', function() { }); }); + it('should handle null amongst valid messages', function(done) { + var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"return [[msg,null,msg],null]"}, + {id:"n2", type:"helper"}, + {id:"n3", type:"helper"}]; + helper.load(functionNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + var n3 = helper.getNode("n3"); + var n2MsgCount = 0; + var n3MsgCount = 0; + n2.on("input", function(msg) { + n2MsgCount++; + }); + n3.on("input", function(msg) { + n3MsgCount++; + }); + n1.receive({payload:"foo",topic: "bar"}); + setTimeout(function() { + n2MsgCount.should.equal(2); + n3MsgCount.should.equal(0); + done(); + },100); + }); + }); it('should handle and log script error', function(done) { var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"retunr"}]; helper.load(functionNode, flow, function() {