Skip to content

Commit 8ad916f

Browse files
committed
[FrameworkBundle] Escape parameters when serializing a ContainerBuilder
1 parent dbedf39 commit 8ad916f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ContainerBuilderDebugDumpPass.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function process(ContainerBuilder $container): void
5454

5555
if (($bag = $container->getParameterBag()) instanceof EnvPlaceholderParameterBag) {
5656
(new ResolveEnvPlaceholdersPass(null))->process($dump);
57-
$dump->__construct(new EnvPlaceholderParameterBag($container->resolveEnvPlaceholders($bag->all())));
57+
$dump->__construct(new EnvPlaceholderParameterBag($container->resolveEnvPlaceholders($this->escapeParameters($bag->all()))));
5858
}
5959

6060
$fs = new Filesystem();
@@ -68,4 +68,18 @@ public function process(ContainerBuilder $container): void
6868
}
6969
}
7070
}
71+
72+
private function escapeParameters(array $parameters): array
73+
{
74+
$params = [];
75+
foreach ($parameters as $k => $v) {
76+
$params[$k] = match (true) {
77+
\is_array($v) => $this->escapeParameters($v),
78+
\is_string($v) => str_replace('%', '%%', $v),
79+
default => $v,
80+
};
81+
}
82+
83+
return $params;
84+
}
7185
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerLintCommandTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static function containerLintProvider(): array
4444
{
4545
return [
4646
['escaped_percent.yml', false, 0, 'The container was linted successfully'],
47+
['escaped_percent.yml', true, 0, 'The container was linted successfully'],
4748
['missing_env_var.yml', false, 0, 'The container was linted successfully'],
4849
['missing_env_var.yml', true, 1, 'Environment variable not found: "BAR"'],
4950
];

0 commit comments

Comments
 (0)