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

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: { defaults: {
name: {value:""}, name: {value:""},
topic: {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"}, payloadType: {value:"date"},
repeat: {value:""}, repeat: {value:""},
crontab: {value:""}, crontab: {value:""},

View File

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