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