From 25bf5ad8f5cfbb419e299c208d95e1169643ad89 Mon Sep 17 00:00:00 2001 From: Marco Otte-Witte Date: Tue, 20 Jun 2017 20:16:50 +0200 Subject: [PATCH] do not override set vars with falsy values (#203) --- lib/main.js | 4 +++- test/main.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index eb96e7fd..5da0ea71 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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 } diff --git a/test/main.js b/test/main.js index 7d6c3cf1..f373ed50 100644 --- a/test/main.js +++ b/test/main.js @@ -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()