Add exception handing to Change node

Adding exception handling to the change node to prevent node-RED from
crashing on invalid regular expressions eg. “*kW” (missing escape
before the asterix)
This commit is contained in:
Frank van de Pol 2013-12-22 14:00:25 +01:00
parent 5d43334b1c
commit 655e777a3e
1 changed files with 7 additions and 3 deletions

View File

@ -35,9 +35,13 @@ function ChangeNode(n) {
this.on('input', function (msg) { this.on('input', function (msg) {
if (node.action == "change") { if (node.action == "change") {
node.re = new RegExp(this.from, "g"); try {
if (typeof msg[node.property] === "string") { node.re = new RegExp(this.from, "g");
msg[node.property] = (msg[node.property]).replace(node.re, node.to); if (typeof msg[node.property] === "string") {
msg[node.property] = (msg[node.property]).replace(node.re, node.to);
}
} catch(err) {
this.error(err.message);
} }
} }
//else if (node.action == "replace") { //else if (node.action == "replace") {