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,10 +35,14 @@ function ChangeNode(n) {
this.on('input', function (msg) {
if (node.action == "change") {
try {
node.re = new RegExp(this.from, "g");
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") {
//if (node.to.indexOf("msg.") == 0) {