diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php index f8af61e6b94c4..14277f86c2512 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php @@ -49,7 +49,7 @@ public function get(string $name): array|bool|string|int|float|\UnitEnum|null } $uniqueName = md5($name.'_'.self::$counter++); - $placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.', '___'), $uniqueName); + $placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.\\', '____'), $uniqueName); $this->envPlaceholders[$env][$placeholder] = $placeholder; return $placeholder; diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index c9a41d3db9b5a..bbf618b981e85 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -51,6 +51,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument; use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; +use Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum; use Symfony\Component\DependencyInjection\Tests\Fixtures\WitherStaticReturnType; use Symfony\Component\DependencyInjection\TypedReference; use Symfony\Component\ExpressionLanguage\Expression; @@ -545,6 +546,23 @@ public function testEnvExpressionFunction() $this->assertEquals('Foo value', $container->get('bar')->foo); } + public function testGetEnvCountersWithEnum() + { + $bag = new EnvPlaceholderParameterBag(); + $config = new ContainerBuilder($bag); + $config->resolveEnvPlaceholders([ + $bag->get('env(enum:'.StringBackedEnum::class.':foo)'), + $bag->get('env(Bar)'), + ]); + + $expected = [ + 'enum:Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum:foo' => 1, + 'Bar' => 1, + ]; + + $this->assertSame($expected, $config->getEnvCounters()); + } + public function testCreateServiceWithAbstractArgument() { $this->expectException(RuntimeException::class);