1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Avoid env var reference loops and support $parent. prefix

Fixes #2099
This commit is contained in:
Nick O'Leary 2019-03-20 13:37:33 +00:00
parent 962a29110c
commit ee6c6266cc
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 44 additions and 10 deletions

View File

@ -68,6 +68,20 @@ class Flow {
}) })
} }
/**
* Log an error-level message from this flow
* @param {[type]} msg [description]
* @return {[type]} [description]
*/
error(msg) {
Log.log({
id: this.id||"global",
level: Log.ERROR,
type:this.TYPE,
msg:msg
})
}
/** /**
* Log a info-level message from this flow * Log a info-level message from this flow
* @param {[type]} msg [description] * @param {[type]} msg [description]

View File

@ -263,17 +263,37 @@ class Subflow extends Flow {
* @return {Object} val value of env var * @return {Object} val value of env var
*/ */
getSetting(name) { getSetting(name) {
var env = this.env; this.trace("getSetting:"+name);
if (env && env.hasOwnProperty(name)) { if (!/^\$parent\./.test(name)) {
var val = env[name]; var env = this.env;
try { if (env && env.hasOwnProperty(name)) {
var ret = redUtil.evaluateNodeProperty(val.value, val.type, this.node, null, null); var val = env[name];
return ret; // If this is an env type property we need to be careful not
} // to get into lookup loops.
catch (e) { // 1. if the value to lookup is the same as this one, go straight to parent
this.error(e); // 2. otherwise, check if it is a compound env var ("foo $(bar)")
return undefined; // and if so, substitute any instances of `name` with $parent.name
// See https://github.com/node-red/node-red/issues/2099
if (val.type !== 'env' || val.value !== name) {
let value = val.value;
if (val.type === 'env') {
value = value.replace(new RegExp("\\${"+name+"}","g"),"${$parent."+name+"}");
}
try {
var ret = redUtil.evaluateNodeProperty(value, val.type, this.node, null, null);
return ret;
}
catch (e) {
this.error(e);
return undefined;
}
} else {
// This _is_ an env property pointing at itself - go to parent
}
} }
} else {
// name starts $parent. ... so delegate to parent automatically
name = name.substring(8);
} }
var parent = this.parent; var parent = this.parent;
if (parent) { if (parent) {