From a337ebcf0d10f0976c1af49191dd151350cb8b32 Mon Sep 17 00:00:00 2001 From: Aurelien Bruno Date: Mon, 2 Dec 2019 22:29:19 +0100 Subject: [PATCH] update getObjectProperty(msg,expr) update getObjectProperty(msg,expr) to support invalid expression to return undefined instead of crashing Quick Check m = {a:{b:{c:{d:{e:"hello"}}}}}; console.log(getMessageProperty(m,"a.b.c.d")) console.log(getMessageProperty(m,"a.j.c.d")) { e: 'hello' } undefined instead of with current code result = ( typeof obj[key] !== "undefined" ? obj[key] : undefined); ^ TypeError: Cannot read property 'c' of undefined --- packages/node_modules/@node-red/util/lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/util/lib/util.js b/packages/node_modules/@node-red/util/lib/util.js index ef43739e6..1930cd6be 100644 --- a/packages/node_modules/@node-red/util/lib/util.js +++ b/packages/node_modules/@node-red/util/lib/util.js @@ -325,7 +325,7 @@ function getObjectProperty(msg,expr) { var msgPropParts = normalisePropertyExpression(expr); var m; msgPropParts.reduce(function(obj, key) { - result = (typeof obj[key] !== "undefined" ? obj[key] : undefined); + result = ((obj && typeof obj[key] !== "undefined") ? obj[key] : undefined); return result; }, msg); return result;