From 1ebc5979aa31159740be2ddbaa2b2194e7f6bbc6 Mon Sep 17 00:00:00 2001 From: Frank van de Pol Date: Tue, 24 Dec 2013 20:28:08 +0100 Subject: [PATCH] Add validation to Change node editor for invalid regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds input validation to the gui of Change Nodes to prevent the user from unintentionally entering an invalid regular expression (in case the ‘use regular expressions’ option is enabled). The user will be notified (using the RED notification mechanism) on the specific error code to help resolve the issue. --- nodes/core/logic/15-change.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nodes/core/logic/15-change.html b/nodes/core/logic/15-change.html index 9d8ad6652..cfcc11817 100644 --- a/nodes/core/logic/15-change.html +++ b/nodes/core/logic/15-change.html @@ -61,7 +61,18 @@ defaults: { action: {value:"change",required:true}, property: {value:"payload"}, - from: {value:""}, + from: {value:"",validate: function(v) { + if (this.action == "change" && this.reg) { + try { + var re = new RegExp(this.from, "g"); + return true; + } catch(err) { + RED.notify("Error: "+err.message,"error"); + return false; + } + } + return true; + }}, to: {value:""}, reg: {value:false}, name: {value:""}