From 22772ca33e81031a3c7ec786e908dfffb8a72a65 Mon Sep 17 00:00:00 2001 From: Hiroki Uchikawa <31908137+HirokiUchikawa@users.noreply.github.com> Date: Mon, 23 Oct 2017 19:13:28 +0900 Subject: [PATCH] Fix debug message format for Buffer (#1444) and add a test case --- nodes/core/core/58-debug.js | 2 +- test/nodes/core/core/58-debug_spec.js | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/nodes/core/core/58-debug.js b/nodes/core/core/58-debug.js index ccb9efc45..083fcb78b 100644 --- a/nodes/core/core/58-debug.js +++ b/nodes/core/core/58-debug.js @@ -138,7 +138,7 @@ module.exports = function(RED) { value = value.substring(0,debuglength)+"..."; } } else if (value && value.constructor) { - if (value.constructor.name === "Buffer") { + if (value.type === "Buffer") { value.__encoded__ = true; value.length = value.data.length; if (value.length > debuglength) { diff --git a/test/nodes/core/core/58-debug_spec.js b/test/nodes/core/core/58-debug_spec.js index 901016da9..a136736c3 100644 --- a/test/nodes/core/core/58-debug_spec.js +++ b/test/nodes/core/core/58-debug_spec.js @@ -449,6 +449,34 @@ describe('debug node', function() { }); }); + it('should truncate a large buffer in the object', function(done) { + var flow = [{id:"n1", type:"debug"}]; + helper.load(debugNode, flow, function() { + var n1 = helper.getNode("n1"); + websocket_test(function() { + n1.emit("input", {payload: {foo: Buffer(1001).fill("X")}}); + }, function(msg) { + var a = JSON.parse(msg); + a.should.eql({ + topic:"debug", + data:{ + id:"n1", + msg:JSON.stringify({ + foo:{ + type: "Buffer", + data: Array(1000).fill(88), + __encoded__: true, + length: 1001 + } + },null," "), + property:"payload", + format:"Object" + } + }); + }, done); + }); + }); + it('should convert Buffer to hex', function(done) { var flow = [{id:"n1", type:"debug" }]; helper.load(debugNode, flow, function() {