Skip to content

Commit

Permalink
Merge branch 'master' of github.com:motdotla/dotenv-expand
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Nov 13, 2024
2 parents 74a397c + 54bcda0 commit 176b153
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ function interpolate (value, processEnv, parsed) {

if (parsed[key]) {
// avoid recursion from EXPAND_SELF=$EXPAND_SELF
if (parsed[key] === value) {
return parsed[key]
} else {
if (parsed[key] !== value) {
return interpolate(parsed[key], processEnv, parsed)
}
}
Expand Down
17 changes: 15 additions & 2 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ t.test('expands self without a recursive call stack error', ct => {
}
const parsed = dotenvExpand.expand(dotenv).parsed

ct.equal(parsed.EXPAND_SELF, '$EXPAND_SELF') // because it ends up accessing parsed[key].
ct.equal(parsed.EXPAND_SELF, '') // because it ends up accessing parsed[key].

ct.end()
})

t.test('expands self with undefined variable and default value', ct => {
const dotenv = {
parsed: {
EXPAND_SELF: '${EXPAND_SELF:-default}'
}
}
const parsed = dotenvExpand.expand(dotenv).parsed

ct.equal(parsed.EXPAND_SELF, 'default')

ct.end()
})
Expand Down Expand Up @@ -466,7 +479,7 @@ t.test('expands self without a recursive call stack error (process.env)', ct =>
const dotenv = require('dotenv').config({ path: 'tests/.env.test', processEnv: {} })
const parsed = dotenvExpand.expand(dotenv).parsed

ct.equal(parsed.EXPAND_SELF, '$EXPAND_SELF') // because it ends up accessing parsed[key].
ct.equal(parsed.EXPAND_SELF, '') // because it ends up accessing parsed[key].

ct.end()
})
Expand Down

0 comments on commit 176b153

Please sign in to comment.