-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[config] cannotBeEmpty does not work with booleanNode #13736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What do you want to achieve ? This is the normal behavior of the For scalar nodes, if you want to invalidate empty strings but keep $rootNode
->children()
->scalarNode('scalar')
->isRequired()
->validate()
->ifTrue(function ($v) {return '' === $v;})
->thenInvalid('Cannot be the empty string')
->end()
->end(); |
@florianv I understand how empty() works, and I understand how to work around this issue. The main issue here, is that one does expect the functionality of "cannotBeEmpty" to work only in certain cases.. on a booleanNode, using either I would propose that (there are precedents in this matter btw.. there is a |
Can you clarify what does "empty bool" mean for you? What do you expect from this constraint? I'd expect an exception as |
Why is that? Because cannotBeEmpty implies that you must specify a value. 'False' is indeed a value, even though an implementation decided otherwise. It would be perfectly valid to ask the user to set an option on the config, which they must explicitly do so, without a default value. Imho, it makes no sense to me to be able to use cannotbeempty on a boolean, where you can only supply the value 'true'. I would propose this to change. In a boolean context false is a perfectly valid option (in fact, it makes up 50% of the valid options). |
|
Yes. You are correct. Cannotbeempty implies that the value cannot be empty. Specifying a value false, is in fact suplying a value. The confusing part is that false is in this case threated as an empty. I understand that this is due to the implementation if empty(), but imho its not the same thing in this context |
I agree that the current implementation is wrong. It's not only with |
see #15170 |
This PR was merged into the 2.3 branch. Discussion ---------- [Config] type specific check for emptiness | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13736 | License | MIT | Doc PR | Commits ------- 0199fbf [Config] type specific check for emptiness
An issue that somebody found:
when using: use_mock: false in the config, it will throw a
InvalidConfigurationException
:The path "config.use_mock" cannot contain an empty value, but got false.
This will be thrown at line:
symfony/src/Symfony/Component/Config/Definition/VariableNode.php
Line 87 in 7185d50
empty()
check on the booleanfalse
will actually return true.Is this a bug, or are there other ways to deal with booleanNodes in this situation?
Gist: https://gist.github.com/jaytaph/08906a3f38ca9f0867f8
(Same issue occurs when using a scalarNode() and using "0" as the config value)
The text was updated successfully, but these errors were encountered: