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:
parent
5d43334b1c
commit
655e777a3e
@ -35,10 +35,14 @@ function ChangeNode(n) {
|
|||||||
|
|
||||||
this.on('input', function (msg) {
|
this.on('input', function (msg) {
|
||||||
if (node.action == "change") {
|
if (node.action == "change") {
|
||||||
|
try {
|
||||||
node.re = new RegExp(this.from, "g");
|
node.re = new RegExp(this.from, "g");
|
||||||
if (typeof msg[node.property] === "string") {
|
if (typeof msg[node.property] === "string") {
|
||||||
msg[node.property] = (msg[node.property]).replace(node.re, node.to);
|
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") {
|
||||||
//if (node.to.indexOf("msg.") == 0) {
|
//if (node.to.indexOf("msg.") == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user