diff --git a/lib/config/core.js b/lib/config/core.js index b9851f98d0e0c..1beca6a509436 100644 --- a/lib/config/core.js +++ b/lib/config/core.js @@ -411,11 +411,23 @@ function envReplace (f) { return f.replace(envExpr, function (orig, esc, name) { esc = esc.length && esc.length % 2 if (esc) return orig - if (undefined === process.env[name]) { - throw new Error('Failed to replace env in config: ' + orig) + var failbackExpr = /(\\*)-/g + var failbackMatch + var failback + while ((failbackMatch = failbackExpr.exec(name))) { + esc = failbackMatch[1] + esc = esc.length && esc.length % 2 + if (esc) continue + failback = name.slice(failbackMatch.index + 1) + name = name.slice(0, failbackMatch.index) + break } - - return process.env[name] + if (undefined !== process.env[name]) { + return process.env[name] + } else if (failbackMatch) { + return failback + } + throw new Error('Failed to replace env in config: ' + orig) }) }