mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3899 from node-red/fix-change-self-overwrite
Fix change node overwriting msg with itself
This commit is contained in:
commit
318f0f1b7e
@ -318,7 +318,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
var r = node.rules[currentRule];
|
var r = node.rules[currentRule];
|
||||||
if (r.t === "move") {
|
if (r.t === "move") {
|
||||||
if ((r.tot !== r.pt) || (r.p.indexOf(r.to) !== -1)) {
|
if ((r.tot !== r.pt) || (r.p.indexOf(r.to) !== -1) && (r.p !== r.to)) {
|
||||||
applyRule(msg,{t:"set", p:r.to, pt:r.tot, to:r.p, tot:r.pt},(err,msg) => {
|
applyRule(msg,{t:"set", p:r.to, pt:r.tot, to:r.p, tot:r.pt},(err,msg) => {
|
||||||
applyRule(msg,{t:"delete", p:r.p, pt:r.pt}, (err,msg) => {
|
applyRule(msg,{t:"delete", p:r.p, pt:r.pt}, (err,msg) => {
|
||||||
completeApplyingRules(msg,currentRule,done);
|
completeApplyingRules(msg,currentRule,done);
|
||||||
|
@ -1717,6 +1717,24 @@ describe('change Node', function() {
|
|||||||
changeNode1.receive({topic:{foo:{bar:1}}, payload:"String"});
|
changeNode1.receive({topic:{foo:{bar:1}}, payload:"String"});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('moves the value of a message property object to itself', function(done) {
|
||||||
|
var flow = [{"id":"changeNode1","type":"change","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||||
|
{id:"helperNode1", type:"helper", wires:[]}];
|
||||||
|
helper.load(changeNode, flow, function() {
|
||||||
|
var changeNode1 = helper.getNode("changeNode1");
|
||||||
|
var helperNode1 = helper.getNode("helperNode1");
|
||||||
|
helperNode1.on("input", function(msg) {
|
||||||
|
try {
|
||||||
|
msg.should.have.property('payload');
|
||||||
|
msg.payload.should.equal("bar");
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
changeNode1.receive({payload:"bar"});
|
||||||
|
});
|
||||||
|
});
|
||||||
it('moves the value of a message property object to a sub-property', function(done) {
|
it('moves the value of a message property object to a sub-property', function(done) {
|
||||||
var flow = [{"id":"changeNode1","type":"change","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.foo","tot":"msg"}],"name":"changeNode","wires":[["helperNode1"]]},
|
var flow = [{"id":"changeNode1","type":"change","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.foo","tot":"msg"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper", wires:[]}];
|
{id:"helperNode1", type:"helper", wires:[]}];
|
||||||
|
Loading…
Reference in New Issue
Block a user