mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Ensure join node handles missing buffer joiner when not in string mode
and add tests to close #2491
This commit is contained in:
parent
32aa4c41ce
commit
5090b01b8e
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="split">
|
||||
<script type="text/html" data-template-name="split">
|
||||
<div class="form-row"><span data-i18n="[html]split.intro"></span></div>
|
||||
<div class="form-row"><span data-i18n="[html]split.strBuff"></span></div>
|
||||
<div class="form-row">
|
||||
@ -113,7 +113,7 @@
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="join">
|
||||
<script type="text/html" data-template-name="join">
|
||||
<div class="form-row">
|
||||
<label data-i18n="join.mode.mode"></label>
|
||||
<select id="node-input-mode" style="width:200px;">
|
||||
|
@ -292,7 +292,6 @@ module.exports = function(RED) {
|
||||
reduceMessageGroup(node,msgs,exp,fixup,count,result,done);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
function reduceAndSendGroup(node, group, done) {
|
||||
var is_right = node.reduce_right;
|
||||
@ -331,7 +330,7 @@ module.exports = function(RED) {
|
||||
var pending_count = node.pending_count;
|
||||
var gid = msg.parts.id;
|
||||
var count;
|
||||
if(!pending.hasOwnProperty(gid)) {
|
||||
if (!pending.hasOwnProperty(gid)) {
|
||||
if(parts.hasOwnProperty('count')) {
|
||||
count = msg.parts.count;
|
||||
}
|
||||
@ -361,7 +360,6 @@ module.exports = function(RED) {
|
||||
}
|
||||
return done();
|
||||
}
|
||||
|
||||
if (msgs.length === group.count) {
|
||||
delete pending[gid];
|
||||
pending_count -= msgs.length;
|
||||
@ -408,7 +406,7 @@ module.exports = function(RED) {
|
||||
if (this.joinerType === "str") {
|
||||
this.joiner = this.joiner.replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g,"\t").replace(/\\e/g,"\e").replace(/\\f/g,"\f").replace(/\\0/g,"\0");
|
||||
} else if (this.joinerType === "bin") {
|
||||
var joinArray = JSON.parse(n.joiner)
|
||||
var joinArray = JSON.parse(n.joiner || "[]");
|
||||
if (Array.isArray(joinArray)) {
|
||||
this.joiner = Buffer.from(joinArray);
|
||||
} else {
|
||||
@ -448,6 +446,9 @@ module.exports = function(RED) {
|
||||
buffers.push(joinBuffer);
|
||||
bufferLen += joinBuffer.length;
|
||||
}
|
||||
if (!Buffer.isBuffer(group.payload[i])) {
|
||||
group.payload[i] = Buffer.from(group.payload[i]);
|
||||
}
|
||||
buffers.push(group.payload[i]);
|
||||
bufferLen += group.payload[i].length;
|
||||
}
|
||||
|
@ -517,6 +517,49 @@ describe('JOIN node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should join things into an array after a count with a buffer join set', function(done) {
|
||||
var flow = [{id:"n1", type:"join", wires:[["n2"]], count:3, joinerType:"bin", joiner:"" ,mode:"custom"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.should.be.an.Array();
|
||||
msg.payload[0].should.equal(1);
|
||||
msg.payload[1].should.equal(true);
|
||||
//msg.payload[2].a.should.equal(1);
|
||||
done();
|
||||
}
|
||||
catch(e) {done(e);}
|
||||
});
|
||||
n1.receive({payload:1});
|
||||
n1.receive({payload:true});
|
||||
n1.receive({payload:{a:1}});
|
||||
});
|
||||
});
|
||||
|
||||
it('should join strings into a buffer after a count', function(done) {
|
||||
var flow = [{id:"n1", type:"join", wires:[["n2"]], count:2, build:"buffer", joinerType:"bin", joiner:"", mode:"custom"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.length.should.equal(10);
|
||||
msg.payload.toString().should.equal("helloworld");
|
||||
done();
|
||||
}
|
||||
catch(e) {done(e);}
|
||||
});
|
||||
n1.receive({payload:"hello"});
|
||||
n1.receive({payload:"world"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should join things into an object after a count', function(done) {
|
||||
var flow = [{id:"n1", type:"join", wires:[["n2"]], count:5, build:"object", mode:"custom"},
|
||||
{id:"n2", type:"helper"}];
|
||||
|
Loading…
Reference in New Issue
Block a user