Merge pull request #4900 from hardillb/allow-number-user-properties-mqtt

Allow msg.userProperties to have number values
This commit is contained in:
Nick O'Leary 2024-10-09 10:28:55 +01:00 committed by GitHub
commit 8988176c22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -158,9 +158,16 @@ module.exports = function(RED) {
if(!keys || !keys.length) return null; if(!keys || !keys.length) return null;
keys.forEach(key => { keys.forEach(key => {
let val = srcUserProperties[key]; let val = srcUserProperties[key];
if(typeof val == "string") { if(typeof val === "string") {
count++; count++;
_clone[key] = val; _clone[key] = val;
} else if (val !== undefined && val !== null) {
try {
_clone[key] = JSON.stringify(val)
count++;
} catch (err) {
// Silently drop property
}
} }
}); });
if(count) properties.userProperties = _clone; if(count) properties.userProperties = _clone;