Skip to content

Commit

Permalink
Fix env fallback to an unresolved variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse authored and nicolas-grekas committed Dec 17, 2018
1 parent 8a60907 commit ad6df01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -1534,11 +1534,15 @@ protected function getEnv($name)
return $value;
}

foreach ($bag->getEnvPlaceholders() as $env => $placeholders) {
if (isset($placeholders[$value])) {
$bag = new ParameterBag($bag->all());
$envPlaceholders = $bag->getEnvPlaceholders();
if (isset($envPlaceholders[$name][$value])) {
$bag = new ParameterBag($bag->all());

return $bag->unescapeValue($bag->get("env($name)"));
return $bag->unescapeValue($bag->get("env($name)"));
}
foreach ($envPlaceholders as $env => $placeholders) {
if (isset($placeholders[$value])) {
return $this->getEnv($env);
}
}

Expand Down
Expand Up @@ -738,6 +738,20 @@ public function testDynamicEnv()
$this->assertSame('someFooBar', $container->getParameter('baz'));
}

public function testFallbackEnv()
{
putenv('DUMMY_FOO=foo');

$container = new ContainerBuilder();
$container->setParameter('foo', '%env(DUMMY_FOO)%');
$container->setParameter('bar', 'bar%env(default:foo:DUMMY_BAR)%');

$container->compile(true);
putenv('DUMMY_FOO');

$this->assertSame('barfoo', $container->getParameter('bar'));
}

public function testCastEnv()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit ad6df01

Please sign in to comment.