diff --git a/lib/main.js b/lib/main.js index ee1004c..794f3bf 100644 --- a/lib/main.js +++ b/lib/main.js @@ -11,8 +11,11 @@ function expandValue (value, processEnv, runningParsed) { let result = value let match + const seen = new Set() // self-referential checker while ((match = regex.exec(result)) !== null) { + seen.add(result) + const [template, bracedExpression, unbracedExpression] = match const expression = bracedExpression || unbracedExpression @@ -38,12 +41,17 @@ function expandValue (value, processEnv, runningParsed) { } if (value) { - result = result.replace(template, value) + // self-referential check + if (seen.has(value)) { + result = result.replace(template, defaultValue) + } else { + result = result.replace(template, value) + } } else { result = result.replace(template, defaultValue) } - // if the result equaled what was in runningParsed then stop expanding - handle self-referential check as well + // if the result equaled what was in process.env and runningParsed then stop expanding if (result === runningParsed[key]) { break }