Fix crash on repeated inject of invalid json payload

This commit is contained in:
Nick O'Leary 2016-02-26 10:35:15 +00:00
parent 0d1543ee8a
commit 859a7538e1
2 changed files with 31 additions and 12 deletions

View File

@ -172,7 +172,22 @@
defaults: {
name: {value:""},
topic: {value:""},
payload: {value:""},
payload: {value:"", validate:function(v) {
var ptype = $("#node-input-payloadType").val() || this.payloadType;
if (ptype === 'json') {
try {
JSON.parse(v);
return true;
} catch(err) {
return false;
}
} else if (ptype === 'flow' || ptype === 'global' ) {
return /^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]+)*/i.test(v);
} else if (ptype === 'num') {
return /^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v);
}
return true;
}},
payloadType: {value:"date"},
repeat: {value:""},
crontab: {value:""},

View File

@ -50,18 +50,22 @@ module.exports = function(RED) {
}
this.on("input",function(msg) {
var msg = {topic:this.topic};
if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
msg.payload = Date.now();
} else if (this.payloadType == null) {
msg.payload = this.payload;
} else if (this.payloadType == 'none') {
msg.payload = "";
} else {
msg.payload = RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg);
try {
msg = {topic:this.topic};
if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
msg.payload = Date.now();
} else if (this.payloadType == null) {
msg.payload = this.payload;
} else if (this.payloadType == 'none') {
msg.payload = "";
} else {
msg.payload = RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg);
}
this.send(msg);
msg = null;
} catch(err) {
this.error(err,msg);
}
this.send(msg);
msg = null;
});
}