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

Fix debug message format for Buffer (#1444)

and add a test case
This commit is contained in:
Hiroki Uchikawa 2017-10-23 19:13:28 +09:00 committed by Nick O'Leary
parent dba6ff1d51
commit 22772ca33e
2 changed files with 29 additions and 1 deletions

View File

@ -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) {

View File

@ -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() {