Skip to content

Commit

Permalink
do not override set vars with falsy values (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow authored and maxbeatty committed Jun 20, 2017
1 parent 825c1b2 commit 25bf5ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ function config (options) {
var parsedObj = parse(fs.readFileSync(path, { encoding: encoding }))

Object.keys(parsedObj).forEach(function (key) {
process.env[key] = process.env[key] || parsedObj[key]
if (!process.env.hasOwnProperty(key)) {
process.env[key] = parsedObj[key]
}
})

return { parsed: parsedObj }
Expand Down
9 changes: 9 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ describe('dotenv', function () {
done()
})

it('does not write over keys already in process.env if the key has a falsy value', function (done) {
process.env.test = ''
// 'val' returned as value in `beforeEach`. should keep this ''
dotenv.config()

process.env.test.should.eql('')
done()
})

it('returns parsed object', function (done) {
var env = dotenv.config()

Expand Down

0 comments on commit 25bf5ad

Please sign in to comment.