Skip to content

Commit e7ccb96

Browse files
bug #50101 [DependencyInjection] Fix support for empty env vars (nicolas-grekas)
This PR was merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Fix support for empty env vars | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50094 | License | MIT | Doc PR | - Commits ------- d86c42e [DependencyInjection] Fix support for empty env vars
2 parents 74ad684 + d86c42e commit e7ccb96

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
149149
|| false === ($env = $env ?? getenv($name) ?? false) // null is a possible value because of thread safety issues
150150
) {
151151
foreach ($this->loadedVars as $vars) {
152-
if (false !== ($env = ($vars[$name] ?? false)) && '' !== $env) {
152+
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
153153
break;
154154
}
155155
}
@@ -167,7 +167,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
167167
continue;
168168
}
169169
$this->loadedVars[] = $vars = $loader->loadEnvVars();
170-
if (false !== ($env = ($vars[$name] ?? false)) && '' !== $env) {
170+
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
171171
$ended = false;
172172
break;
173173
}

src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ public static function validCsv()
727727
public function testEnvLoader()
728728
{
729729
$_ENV['BAZ_ENV_LOADER'] = '';
730+
$_ENV['BUZ_ENV_LOADER'] = '';
730731

731732
$loaders = function () {
732733
yield new class() implements EnvVarLoaderInterface {
@@ -751,7 +752,7 @@ public function loadEnvVars(): array
751752
};
752753
};
753754

754-
$processor = new EnvVarProcessor(new Container(), $loaders());
755+
$processor = new EnvVarProcessor(new Container(), new RewindableGenerator($loaders, 2));
755756

756757
$result = $processor->getEnv('string', 'FOO_ENV_LOADER', function () {});
757758
$this->assertSame('123', $result);
@@ -762,10 +763,14 @@ public function loadEnvVars(): array
762763
$result = $processor->getEnv('string', 'BAZ_ENV_LOADER', function () {});
763764
$this->assertSame('567', $result);
764765

766+
$result = $processor->getEnv('string', 'BUZ_ENV_LOADER', function () {});
767+
$this->assertSame('', $result);
768+
765769
$result = $processor->getEnv('string', 'FOO_ENV_LOADER', function () {});
766770
$this->assertSame('123', $result); // check twice
767771

768772
unset($_ENV['BAZ_ENV_LOADER']);
773+
unset($_ENV['BUZ_ENV_LOADER']);
769774
}
770775

771776
public function testCircularEnvLoader()

0 commit comments

Comments
 (0)