Merge pull request #4411 from node-red/4376-handle-falsy-env-vars

Handle false-like env vars properly
This commit is contained in:
Nick O'Leary 2023-11-07 17:40:18 +00:00 committed by GitHub
commit 409a559a13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -109,9 +109,8 @@ module.exports = function(RED) {
} }
const p = props.shift() const p = props.shift()
const property = p.p; const property = p.p;
const value = p.v ? p.v : ''; const value = p.v !== undefined ? p.v : '';
const valueType = p.vt ? p.vt : 'str'; const valueType = p.vt !== undefined ? p.vt : 'str';
if (property) { if (property) {
if (valueType === "jsonata") { if (valueType === "jsonata") {
if (p.v) { if (p.v) {

View File

@ -57,18 +57,20 @@ var EnvVarPropertyRE = /^\${(\S+)}$/;
function mapEnvVarProperties(obj,prop,flow,config) { function mapEnvVarProperties(obj,prop,flow,config) {
var v = obj[prop]; const v = obj[prop];
if (Buffer.isBuffer(v)) { if (Buffer.isBuffer(v)) {
return; return;
} else if (Array.isArray(v)) { } else if (Array.isArray(v)) {
for (var i=0;i<v.length;i++) { for (let i=0;i<v.length;i++) {
mapEnvVarProperties(v,i,flow,config); mapEnvVarProperties(v,i,flow,config);
} }
} else if (typeof obj[prop] === 'string') { } else if (typeof obj[prop] === 'string') {
if (obj[prop][0] === "$" && (EnvVarPropertyRE_old.test(v) || EnvVarPropertyRE.test(v)) ) { if (obj[prop][0] === "$" && (EnvVarPropertyRE_old.test(v) || EnvVarPropertyRE.test(v)) ) {
var envVar = v.substring(2,v.length-1); const envVar = v.substring(2,v.length-1);
var r = redUtil.getSetting(config, envVar, flow); const r = redUtil.getSetting(config, envVar, flow);
obj[prop] = r ? r : obj[prop]; if (r !== undefined && r !== '') {
obj[prop] = r
}
} }
} else { } else {
for (var p in v) { for (var p in v) {