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

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

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") {