From 022db9c8a309fcd7cd58bf7d6fc066acd411a679 Mon Sep 17 00:00:00 2001 From: Jason Rowsell <76700693+jasonrowsell@users.noreply.github.com> Date: Wed, 21 Dec 2022 19:05:06 +0000 Subject: [PATCH] fix(Variables): Support empty string environment variables (#11629) --- lib/configuration/variables/sources/env.js | 7 +++++-- test/unit/lib/configuration/variables/sources/env.test.js | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/configuration/variables/sources/env.js b/lib/configuration/variables/sources/env.js index 91fe1d737da..202b2efecbc 100644 --- a/lib/configuration/variables/sources/env.js +++ b/lib/configuration/variables/sources/env.js @@ -21,8 +21,11 @@ module.exports = { errorCode: 'INVALID_ENV_SOURCE_ADDRESS', }); - if (!process.env[address]) missingEnvVariables.add(address); - return { value: process.env[address] || null, isPending: !isSourceFulfilled }; + if (process.env[address] == null) missingEnvVariables.add(address); + return { + value: process.env[address] == null ? null : process.env[address], + isPending: !isSourceFulfilled, + }; }, missingEnvVariables, }; diff --git a/test/unit/lib/configuration/variables/sources/env.test.js b/test/unit/lib/configuration/variables/sources/env.test.js index e0411e7e2fe..fce3d6aa960 100644 --- a/test/unit/lib/configuration/variables/sources/env.test.js +++ b/test/unit/lib/configuration/variables/sources/env.test.js @@ -12,9 +12,11 @@ describe('test/unit/lib/configuration/variables/sources/env.test.js', () => { let variablesMeta; before(async () => { process.env.ENV_SOURCE_TEST = 'foobar'; + process.env.ENV_SOURCE_TEST_EMPTY = ''; configuration = { env: '${env:ENV_SOURCE_TEST}', envMissing: "${env:ENV_SOURCE_TEST_MISSING, 'fallback'}", + envEmpty: '${env:ENV_SOURCE_TEST_EMPTY}', noAddress: '${env:}', nonStringAddress: '${env:${self:someObject}}', someObject: {}, @@ -34,6 +36,9 @@ describe('test/unit/lib/configuration/variables/sources/env.test.js', () => { it('should resolve null on missing environment variable', () => expect(configuration.envMissing).to.equal('fallback')); + it('should resolve environment variable that is empty', () => + expect(configuration.envEmpty).to.equal('')); + it('should report with an error missing address argument', () => expect(variablesMeta.get('noAddress').error.code).to.equal('VARIABLE_RESOLUTION_ERROR'));