mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
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
This commit is contained in:
parent
c1dae95f71
commit
a337ebcf0d
@ -325,7 +325,7 @@ function getObjectProperty(msg,expr) {
|
|||||||
var msgPropParts = normalisePropertyExpression(expr);
|
var msgPropParts = normalisePropertyExpression(expr);
|
||||||
var m;
|
var m;
|
||||||
msgPropParts.reduce(function(obj, key) {
|
msgPropParts.reduce(function(obj, key) {
|
||||||
result = (typeof obj[key] !== "undefined" ? obj[key] : undefined);
|
result = ((obj && typeof obj[key] !== "undefined") ? obj[key] : undefined);
|
||||||
return result;
|
return result;
|
||||||
}, msg);
|
}, msg);
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user