Let JSON parser attempt to parse buffers if they contain strings

and add/fix test
This commit is contained in:
Dave Conway-Jones
2021-12-10 15:21:43 +00:00
parent 7cd3e49f04
commit 6ae42eb787
2 changed files with 67 additions and 19 deletions

View File

@@ -49,7 +49,11 @@ module.exports = function(RED) {
}
var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) {
if (typeof value === "string") {
if (typeof value === "string" || Buffer.isBuffer(value)) {
// if (Buffer.isBuffer(value) && node.action !== "obj") {
// node.warn(RED._("json.errors.dropped")); done();
// }
// else
if (node.action === "" || node.action === "obj") {
try {
RED.util.setMessageProperty(msg,node.property,JSON.parse(value));