From 8516f41ba8197f59bc81405b41a4fb52a0f1580e Mon Sep 17 00:00:00 2001 From: Hiroyasu Nishiyama Date: Sun, 28 Jan 2018 14:37:34 +0900 Subject: [PATCH] do not reuse message object for multiple outputs --- nodes/core/parsers/70-HTML.js | 7 ++++--- test/nodes/core/parsers/70-HTML_spec.js | 26 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/nodes/core/parsers/70-HTML.js b/nodes/core/parsers/70-HTML.js index 715c77b6b..16d29883a 100644 --- a/nodes/core/parsers/70-HTML.js +++ b/nodes/core/parsers/70-HTML.js @@ -45,15 +45,16 @@ module.exports = function(RED) { //if (node.ret === "val") { pay2 = $(this).val(); } /* istanbul ignore else */ if (pay2) { - msg.payload = pay2; - msg.parts = { + var new_msg = RED.util.cloneMessage(msg); + new_msg.payload = pay2; + new_msg.parts = { id: msg._msgid, index: index, count: count, type: "string", ch: "" }; - node.send(msg); + node.send(new_msg); } } if (node.as === "single") { diff --git a/test/nodes/core/parsers/70-HTML_spec.js b/test/nodes/core/parsers/70-HTML_spec.js index ed08fac07..1c921bb2d 100644 --- a/test/nodes/core/parsers/70-HTML_spec.js +++ b/test/nodes/core/parsers/70-HTML_spec.js @@ -328,6 +328,32 @@ describe('html node', function() { }); }); + it('should not reuse message', function(done) { + fs.readFile(file, 'utf8', function(err, data) { + var flow = [{id:"n1",type:"html",wires:[["n2"]],tag:"ul",ret:"text",as:"multi"}, + {id:"n2", type:"helper"}]; + + helper.load(htmlNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + var prev_msg = undefined; + n2.on("input", function(msg) { + cnt++; + if (prev_msg == undefined) { + prev_msg = msg; + } + else { + msg.should.not.equal(prev_msg); + } + if (cnt == 2) { + done(); + } + }); + n1.receive({payload:data,topic: "bar"}); + }); + }); + }); + }); });