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

Handle undefined value in Debug view of Array and Object

Fixes #2696
This commit is contained in:
Nick O'Leary 2020-09-07 21:05:27 +01:00
parent 5cf489a270
commit baffe4861c
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 36 additions and 1 deletions

View File

@ -722,6 +722,9 @@ RED.clipboard = (function() {
// representation or null // representation or null
return null; return null;
} }
if (value.type === 'undefined') {
return undefined;
}
} }
} }
return value; return value;

View File

@ -52,7 +52,9 @@ RED.utils = (function() {
} else if (value === null) { } else if (value === null) {
result = $('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-null">null</span>'); result = $('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-null">null</span>');
} else if (typeof value === 'object') { } else if (typeof value === 'object') {
if (value.hasOwnProperty('type') && value.type === 'Buffer' && value.hasOwnProperty('data')) { if (value.hasOwnProperty('type') && value.type === 'undefined') {
result = $('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-null">undefined</span>');
} else if (value.hasOwnProperty('type') && value.type === 'Buffer' && value.hasOwnProperty('data')) {
result = $('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text('buffer['+value.length+']'); result = $('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text('buffer['+value.length+']');
} else if (value.hasOwnProperty('type') && value.type === 'array' && value.hasOwnProperty('data')) { } else if (value.hasOwnProperty('type') && value.type === 'array' && value.hasOwnProperty('data')) {
result = $('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text('array['+value.length+']'); result = $('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text('array['+value.length+']');
@ -348,6 +350,8 @@ RED.utils = (function() {
} }
if (obj === null || obj === undefined) { if (obj === null || obj === undefined) {
$('<span class="red-ui-debug-msg-type-null">'+obj+'</span>').appendTo(entryObj); $('<span class="red-ui-debug-msg-type-null">'+obj+'</span>').appendTo(entryObj);
} else if (obj.__enc__ && obj.type === 'undefined') {
$('<span class="red-ui-debug-msg-type-null">undefined</span>').appendTo(entryObj);
} else if (obj.__enc__ && obj.type === 'number') { } else if (obj.__enc__ && obj.type === 'number') {
e = $('<span class="red-ui-debug-msg-type-number red-ui-debug-msg-object-header"></span>').text(obj.data).appendTo(entryObj); e = $('<span class="red-ui-debug-msg-type-number red-ui-debug-msg-object-header"></span>').text(obj.data).appendTo(entryObj);
} else if (typeHint === "function" || (obj.__enc__ && obj.type === 'function')) { } else if (typeHint === "function" || (obj.__enc__ && obj.type === 'function')) {

View File

@ -771,6 +771,11 @@ function encodeObject(msg,opts) {
} else if (value.constructor.name === "Socket") { } else if (value.constructor.name === "Socket") {
value = "[internal]" value = "[internal]"
} }
} else if (value === undefined) {
value = {
__enc__: true,
type: "undefined",
}
} }
return value; return value;
}," "); }," ");

View File

@ -740,6 +740,19 @@ describe("@node-red/util/util", function() {
resultJson.name.should.eql('my error obj'); resultJson.name.should.eql('my error obj');
resultJson.message.should.eql('my error message'); resultJson.message.should.eql('my error message');
}); });
it('object with undefined property', function() {
var msg = { msg:{a:1,b:undefined,c:3 } };
var result = util.encodeObject(msg);
result.format.should.eql("Object");
var resultJson = JSON.parse(result.msg);
resultJson.should.have.property("a",1);
resultJson.should.have.property("c",3);
resultJson.should.have.property("b");
resultJson.b.should.have.property("__enc__", true);
resultJson.b.should.have.property("type", "undefined");
});
it('constructor of IncomingMessage', function() { it('constructor of IncomingMessage', function() {
function IncomingMessage(){}; function IncomingMessage(){};
var msg = { msg:new IncomingMessage() }; var msg = { msg:new IncomingMessage() };
@ -791,6 +804,16 @@ describe("@node-red/util/util", function() {
resultJson[0].should.eql('abc...'); resultJson[0].should.eql('abc...');
resultJson[1].should.eql('123...'); resultJson[1].should.eql('123...');
}); });
it('array containing undefined', function() {
var msg = { msg:[1,undefined,3]};
var result = util.encodeObject(msg);
result.format.should.eql("array[3]");
var resultJson = JSON.parse(result.msg);
resultJson[0].should.eql(1);
resultJson[2].should.eql(3);
resultJson[1].__enc__.should.be.true();
resultJson[1].type.should.eql("undefined");
});
it('array of function', function() { it('array of function', function() {
var msg = { msg:[function(){}] }; var msg = { msg:[function(){}] };
var result = util.encodeObject(msg); var result = util.encodeObject(msg);