From 655e777a3eaefb3252aad6e4c0a374205a601242 Mon Sep 17 00:00:00 2001 From: Frank van de Pol Date: Sun, 22 Dec 2013 14:00:25 +0100 Subject: [PATCH] Add exception handing to Change node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding exception handling to the change node to prevent node-RED from crashing on invalid regular expressions eg. “*kW” (missing escape before the asterix) --- nodes/core/logic/15-change.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nodes/core/logic/15-change.js b/nodes/core/logic/15-change.js index 4866239c0..5f518987f 100644 --- a/nodes/core/logic/15-change.js +++ b/nodes/core/logic/15-change.js @@ -35,9 +35,13 @@ function ChangeNode(n) { this.on('input', function (msg) { if (node.action == "change") { - node.re = new RegExp(this.from, "g"); - if (typeof msg[node.property] === "string") { - msg[node.property] = (msg[node.property]).replace(node.re, node.to); + 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") {