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

Add check that node sends object rather than primitive type

Fixes #3876
This commit is contained in:
Nick O'Leary 2022-10-04 11:49:49 +01:00
parent 93c1600980
commit a40e5dbcd4
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 31 additions and 21 deletions

View File

@ -373,6 +373,11 @@ Node.prototype.send = function(msg) {
if (msg === null || typeof msg === "undefined") { if (msg === null || typeof msg === "undefined") {
return; return;
} else if (!util.isArray(msg)) { } else if (!util.isArray(msg)) {
// A single message has been passed in
if (typeof msg !== 'object') {
this.error(Log._("nodes.flow.non-message-returned", { type: typeof msg }));
return
}
if (this._wire) { if (this._wire) {
// A single message and a single wire on output 0 // A single message and a single wire on output 0
// TODO: pre-load flows.get calls - cannot do in constructor // TODO: pre-load flows.get calls - cannot do in constructor
@ -425,6 +430,9 @@ Node.prototype.send = function(msg) {
for (k = 0; k < msgs.length; k++) { for (k = 0; k < msgs.length; k++) {
var m = msgs[k]; var m = msgs[k];
if (m !== null && m !== undefined) { if (m !== null && m !== undefined) {
if (typeof m !== 'object') {
this.error(Log._("nodes.flow.non-message-returned", { type: typeof m }));
} else {
if (!m._msgid) { if (!m._msgid) {
hasMissingIds = true; hasMissingIds = true;
} }
@ -452,6 +460,7 @@ Node.prototype.send = function(msg) {
} }
} }
} }
}
/* istanbul ignore else */ /* istanbul ignore else */
if (!sentMessageId) { if (!sentMessageId) {
sentMessageId = redUtil.generateId(); sentMessageId = redUtil.generateId();

View File

@ -134,7 +134,8 @@
"flow": { "flow": {
"unknown-type": "Unknown type: __type__", "unknown-type": "Unknown type: __type__",
"missing-types": "missing types", "missing-types": "missing types",
"error-loop": "Message exceeded maximum number of catches" "error-loop": "Message exceeded maximum number of catches",
"non-message-returned": "Node tried to send a message of type __type__"
}, },
"index": { "index": {
"unrecognised-id": "Unrecognised id: __id__", "unrecognised-id": "Unrecognised id: __id__",