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

Handle invalid property values in Switch node

Fixes #404
This commit is contained in:
Nick O'Leary 2014-09-17 22:31:26 +01:00
parent f04e42e4da
commit ebb0d1a46d

View File

@ -38,8 +38,8 @@ module.exports = function(RED) {
this.rules = n.rules;
this.property = n.property;
this.checkall = n.checkall || "true";
var propertyParts = n.property.split("."),
node = this;
var propertyParts = n.property.split(".");
var node = this;
for (var i=0; i<this.rules.length; i+=1) {
var rule = this.rules[i];
@ -51,23 +51,27 @@ module.exports = function(RED) {
this.on('input', function (msg) {
var onward = [];
var prop = propertyParts.reduce(function (obj, i) {
return obj[i]
}, msg);
var elseflag = true;
for (var i=0; i<node.rules.length; i+=1) {
var rule = node.rules[i];
var test = prop;
if (rule.t == "else") { test = elseflag; elseflag = true; }
if (operators[rule.t](test,rule.v, rule.v2)) {
onward.push(msg);
elseflag = false;
if (node.checkall == "false") { break; }
} else {
onward.push(null);
try {
var prop = propertyParts.reduce(function (obj, i) {
return obj[i]
}, msg);
var elseflag = true;
for (var i=0; i<node.rules.length; i+=1) {
var rule = node.rules[i];
var test = prop;
if (rule.t == "else") { test = elseflag; elseflag = true; }
if (operators[rule.t](test,rule.v, rule.v2)) {
onward.push(msg);
elseflag = false;
if (node.checkall == "false") { break; }
} else {
onward.push(null);
}
}
this.send(onward);
} catch(err) {
node.warn(err);
}
this.send(onward);
});
}
RED.nodes.registerType("switch", SwitchNode);