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:
commit
74f43f4059
@ -61,7 +61,17 @@
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}},
|
||||
to: {value:""},
|
||||
reg: {value:false},
|
||||
name: {value:""}
|
||||
|
@ -43,7 +43,7 @@ function ChangeNode(n) {
|
||||
try {
|
||||
node.re = new RegExp(from, "g");
|
||||
} catch (e) {
|
||||
node.error("Invalid regex: "+from);
|
||||
node.error(e.message);
|
||||
}
|
||||
if (typeof msg[node.property] === "string") {
|
||||
msg[node.property] = (msg[node.property]).replace(node.re, node.to);
|
||||
|
Loading…
Reference in New Issue
Block a user