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

Merge pull request #127 from fvdpol/master

Add validation to the Change node 'from' field
This commit is contained in:
Nick O'Leary 2013-12-24 14:53:48 -08:00
commit 74f43f4059
2 changed files with 12 additions and 2 deletions

View File

@ -61,7 +61,17 @@
defaults: { defaults: {
action: {value:"change",required:true}, action: {value:"change",required:true},
property: {value:"payload"}, 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) {
return false;
}
}
return true;
}},
to: {value:""}, to: {value:""},
reg: {value:false}, reg: {value:false},
name: {value:""} name: {value:""}

View File

@ -43,7 +43,7 @@ function ChangeNode(n) {
try { try {
node.re = new RegExp(from, "g"); node.re = new RegExp(from, "g");
} catch (e) { } catch (e) {
node.error("Invalid regex: "+from); node.error(e.message);
} }
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);