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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 (msgs[m]) {
if (util.isArray(msgs[m])) { if (util.isArray(msgs[m])) {
for (var n=0; n < msgs[m].length; n++) { for (var n=0; n < msgs[m].length; n++) {
msgs[m][n]._msgid = _msgid; if (msgs[m][n] !== null && msgs[m][n] !== undefined) {
msgCount++; msgs[m][n]._msgid = _msgid;
msgCount++;
}
} }
} else { } else {
msgs[m]._msgid = _msgid; if (msgs[m] !== null && msgs[m] !== undefined) {
msgCount++; msgs[m]._msgid = _msgid;
msgCount++;
}
} }
} }
} }

View File

@ -157,16 +157,18 @@ Node.prototype.send = function(msg) {
// for each msg to send eg. [[m1, m2, ...], ...] // for each msg to send eg. [[m1, m2, ...], ...]
for (k = 0; k < msgs.length; k++) { for (k = 0; k < msgs.length; k++) {
var m = msgs[k]; var m = msgs[k];
/* istanbul ignore else */ if (m !== null && m !== undefined) {
if (!sentMessageId) { /* istanbul ignore else */
sentMessageId = m._msgid; if (!sentMessageId) {
} sentMessageId = m._msgid;
if (msgSent) { }
var clonedmsg = redUtil.cloneMessage(m); if (msgSent) {
sendEvents.push({n:node,m:clonedmsg}); var clonedmsg = redUtil.cloneMessage(m);
} else { sendEvents.push({n:node,m:clonedmsg});
sendEvents.push({n:node,m:m}); } else {
msgSent = true; sendEvents.push({n:node,m:m});
msgSent = true;
}
} }
} }
} }

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) { it('should handle and log script error', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"retunr"}]; var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"retunr"}];
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {