bug #26799 [DI][Config] Fix empty env validation (ro0NL)
This PR was merged into the 4.1-dev branch.
Discussion
----------
[DI][Config] Fix empty env validation
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #26747
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
- Bug fixes must be submitted against the lowest branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the master branch.
-->
Commits
-------
d40a4f409d
[DI][Config] Fix empty env validation
This commit is contained in:
commit
dbafc11630
@ -476,6 +476,14 @@ abstract class BaseNode implements NodeInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a placeholder is being handled currently.
|
||||
*/
|
||||
protected function isHandlingPlaceholder(): bool
|
||||
{
|
||||
return null !== $this->handlingPlaceholder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets allowed dynamic types for this node.
|
||||
*/
|
||||
|
@ -52,6 +52,10 @@ class ScalarNode extends VariableNode
|
||||
*/
|
||||
protected function isValueEmpty($value)
|
||||
{
|
||||
if ($this->isHandlingPlaceholder()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return null === $value || '' === $value;
|
||||
}
|
||||
|
||||
|
@ -196,6 +196,19 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
|
||||
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
|
||||
}
|
||||
|
||||
public function testEmptyEnvWithCannotBeEmptyForScalarNode(): void
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension($ext = new EnvExtension());
|
||||
$container->prependExtensionConfig('env_extension', $expected = array(
|
||||
'scalar_node_not_empty' => '%env(SOME)%',
|
||||
));
|
||||
|
||||
$this->doProcess($container);
|
||||
|
||||
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
|
||||
}
|
||||
|
||||
private function doProcess(ContainerBuilder $container): void
|
||||
{
|
||||
(new MergeExtensionConfigurationPass())->process($container);
|
||||
@ -213,6 +226,7 @@ class EnvConfiguration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('scalar_node')->end()
|
||||
->scalarNode('scalar_node_not_empty')->cannotBeEmpty()->end()
|
||||
->integerNode('int_node')->end()
|
||||
->floatNode('float_node')->end()
|
||||
->booleanNode('bool_node')->end()
|
||||
|
Reference in New Issue
Block a user