mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	try to fix debug node non-standard object type handling.
This commit is contained in:
		| @@ -86,15 +86,12 @@ module.exports = function(RED) { | ||||
|             msg.msg = msg.msg.toString('hex'); | ||||
|         } else if (typeof msg.msg === 'object') { | ||||
|             var seen = []; | ||||
|             msg.format = "object"; | ||||
|             msg.format = msg.msg.constructor.name || "Object"; | ||||
|             var isArray = util.isArray(msg.msg); | ||||
|             if (!isArray && msg.msg.toString !== Object.prototype.toString) { | ||||
|                 msg.format = msg.msg.constructor.name || "object"; | ||||
|                 msg.msg = msg.msg.toString(); | ||||
|             } else { | ||||
|                 if (isArray) { | ||||
|                     msg.format = "array ["+msg.msg.length+"]"; | ||||
|                 } | ||||
|             if (isArray) { | ||||
|                 msg.format = "array ["+msg.msg.length+"]"; | ||||
|             } | ||||
|             if (isArray || (msg.format === "Object")) { | ||||
|                 msg.msg = JSON.stringify(msg.msg, function(key, value) { | ||||
|                     if (typeof value === 'object' && value !== null) { | ||||
|                         if (seen.indexOf(value) !== -1) { return "[circular]"; } | ||||
| @@ -102,6 +99,9 @@ module.exports = function(RED) { | ||||
|                     } | ||||
|                     return value; | ||||
|                 }," "); | ||||
|             } else { | ||||
|                 try { msg.msg = msg.msg.toString(); } | ||||
|                 catch(e) { msg.msg = "[Type not printable]"; } | ||||
|             } | ||||
|             seen = null; | ||||
|         } else if (typeof msg.msg === "boolean") { | ||||
|   | ||||
| @@ -94,7 +94,7 @@ describe('debug node', function() { | ||||
|             }, function(msg) { | ||||
|                 JSON.parse(msg).should.eql({ | ||||
|                     topic:"debug", | ||||
|                     data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"object"} | ||||
|                     data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"Object"} | ||||
|                 }); | ||||
|             }, done); | ||||
|         }); | ||||
| @@ -179,7 +179,7 @@ describe('debug node', function() { | ||||
|             }, function(msg) { | ||||
|                 JSON.parse(msg).should.eql({ | ||||
|                     topic:"debug", | ||||
|                     data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"object"} | ||||
|                     data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"Object"} | ||||
|                 }); | ||||
|             }, done); | ||||
|         }); | ||||
| @@ -215,7 +215,7 @@ describe('debug node', function() { | ||||
|                     data:{ | ||||
|                         id:"n1", | ||||
|                         msg:'{\n "name": "bar",\n "o": "[circular]"\n}', | ||||
|                         property:"payload",format:"object" | ||||
|                         property:"payload",format:"Object" | ||||
|                     } | ||||
|                 }); | ||||
|             }, done); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user