From 7f77a414ec44715a1773e25d930a45805b1ccf7a Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 11 Sep 2024 12:10:37 +0100 Subject: [PATCH] Ensure will payload is a string --- .../@node-red/nodes/core/network/10-mqtt.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index 7be0263d6..9e707fa68 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -673,6 +673,8 @@ module.exports = function(RED) { delete node.options.protocolId; //V4+ default delete node.options.protocolVersion; //V4 default delete node.options.properties;//V5 only + + if (node.compatmode == "true" || node.compatmode === true || node.protocolVersion == 3) { node.options.protocolId = 'MQIsdp';//V3 compat only node.options.protocolVersion = 3; @@ -691,6 +693,21 @@ module.exports = function(RED) { setIntProp(node,node.options.properties,"sessionExpiryInterval"); } } + // Ensure will payload, if set, is a string + if (node.options.will && Object.hasOwn(node.options.will, 'payload')) { + let payload = node.options.will.payload + if (payload === null || payload === undefined) { + payload = ""; + } else if (!Buffer.isBuffer(payload)) { + if (typeof payload === "object") { + payload = JSON.stringify(payload); + } else if (typeof payload !== "string") { + payload = "" + payload; + } + } + node.options.will.payload = payload + } + if (node.usetls && n.tls) { var tlsNode = RED.nodes.getNode(n.tls); if (tlsNode) {