8000 [DI][Config] Fix empty env validation · symfony/symfony@d40a4f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit d40a4f4

Browse files
committed
[DI][Config] Fix empty env validation
1 parent e973f6f commit d40a4f4

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Symfony/Component/Config/Definition/BaseNode.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,14 @@ protected function allowPlaceholders(): bool
476476
return true;
477477
}
478478

479+
/**
480+
* Tests if a placeholder is being handled currently.
481+
*/
482+
protected function isHandlingPlaceholder(): bool
483+
{
484+
return null !== $this->handlingPlaceholder;
485+
}
486+
479487
/**
480488
* Gets allowed dynamic types for this node.
481489
*/

src/Symfony/Component/Config/Definition/ScalarNode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ protected function validateType($value)
5252
*/
5353
protected function isValueEmpty($value)
5454
{
55+
if ($this->isHandlingPlaceholder()) {
56+
return false;
57+
}
58+
5559
return null === $value || '' === $value;
5660
}
5761

src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ public function testEnvIsNotUnset()
196196
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
197197
}
198198

199+
public function testEmptyEnvWithCannotBeEmptyForScalarNode(): void
200+
{
201+
$container = new ContainerBuilder();
202+
$container->registerExtension($ext = new EnvExtension());
203+
$container->prependExtensionConfig('env_extension', $expected = array(
204+
'scalar_node_not_empty' => '%env(SOME)%',
205+
));
206+
207+
$this->doProcess($container);
208+
209+
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
210+
}
211+
199212
private function doProcess(ContainerBuilder $container): void
200213
{
201214
(new MergeExtensionConfigurationPass())->process($container);
@@ -213,6 +226,7 @@ public function getConfigTreeBuilder()
213226
$rootNode
214227
->children()
215228
->scalarNode('scalar_node')->end()
229+
->scalarNode('scalar_node_not_empty')->cannotBeEmpty()->end()
216230
->integerNode('int_node')->end()
217231
->floatNode('float_node')->end()
218232
->booleanNode('bool_node')->end()

0 commit comments

Comments
 (0)
0