Ensure will payload is a string

This commit is contained in:
Nick O'Leary 2024-09-11 12:10:37 +01:00
parent edc01552f9
commit 7f77a414ec
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

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