Skip to content

Commit

Permalink
fix(Variables): Support empty string environment variables (#11629)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrowsell committed Dec 21, 2022
1 parent 968ddd5 commit 022db9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/configuration/variables/sources/env.js
Expand Up @@ -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,
};
5 changes: 5 additions & 0 deletions test/unit/lib/configuration/variables/sources/env.test.js
Expand Up @@ -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: {},
Expand All @@ -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'));

Expand Down

0 comments on commit 022db9c

Please sign in to comment.