1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Handle null return from Function node in array of messages

This commit is contained in:
Nick O'Leary 2016-06-06 11:40:02 +01:00
parent ea76c18f59
commit 3959fcdc88
3 changed files with 45 additions and 15 deletions

View File

@ -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,15 +30,19 @@ module.exports = function(RED) {
if (msgs[m]) {
if (util.isArray(msgs[m])) {
for (var n=0; n < msgs[m].length; n++) {
if (msgs[m][n] !== null && msgs[m][n] !== undefined) {
msgs[m][n]._msgid = _msgid;
msgCount++;
}
}
} else {
if (msgs[m] !== null && msgs[m] !== undefined) {
msgs[m]._msgid = _msgid;
msgCount++;
}
}
}
}
if (msgCount>0) {
node.send(msgs);
}

View File

@ -157,6 +157,7 @@ Node.prototype.send = function(msg) {
// for each msg to send eg. [[m1, m2, ...], ...]
for (k = 0; k < msgs.length; k++) {
var m = msgs[k];
if (m !== null && m !== undefined) {
/* istanbul ignore else */
if (!sentMessageId) {
sentMessageId = m._msgid;
@ -174,6 +175,7 @@ Node.prototype.send = function(msg) {
}
}
}
}
/* istanbul ignore else */
if (!sentMessageId) {
sentMessageId = redUtil.generateId();

View File

@ -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() {