mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Fix crash on repeated inject of invalid json payload
This commit is contained in:
		| @@ -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:""}, | ||||
|   | ||||
| @@ -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; | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user