#106443BooleanValidator should interpret empty string as `false` But does not deal with empty values.
Description
The AbstractValidator returns the validate method early for any empty value including empty strings if $acceptsEmptyValues is set to true (the default).
The boolean validator expecitely tests if a string is empty:
case 'false':
case '':
case '0':
$expectation = false;
break;
However as empty strings are filtered out before we ever get here, An empty string will never reach this point.
Changing this behaviour might be breaking for those who already rely on it.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 7
-
Garvin Hicking changed category <span data-processor="relativetime" data-value="2025-03-27T07:03:00+00:00" > 03/27/25, 07:03 </span>
-
Mathias Brodala changed description <span data-processor="relativetime" data-value="2025-03-27T07:52:36+00:00" > 03/27/25, 07:52 </span>
-
Georg Ringer commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2025-04-16T14:49:14+00:00" > 04/16/25, 14:49 </span> -
Lina Wolf commented <span data-processor="relativetime" data-value="2025-04-25T14:45:10+00:00" > 04/25/25, 14:45 </span>
If we have a f:form.checkbox bound to a parameter and the check box is not checked null will be passed to the parameter, not false (As the value is not send at all by the form).
It deems me counterintuitive that a validator checking for the value to be true would still be valid in such a case. Commonly an unchecked checkbox is considered to be false and not undefined. -
Lina Wolf changed status
Needs FeedbackNew <span data-processor="relativetime" data-value="2025-04-25T14:45:29+00:00" > 04/25/25, 14:45 </span> -
Torben Hansen commented <span data-processor="relativetime" data-value="2026-02-06T18:19:36+00:00" > 02/06/26, 18:19 </span>
The BooleanValidator for sure has some backdraws (see todo comments in class), but from an technical perspective, it works as intended. It should be used for a
booleanproperty either in an extbase domain model or DTO and in scenarios, where the extbase property mapper is involved.#[Validate(['validator' => BooleanValidator::class, 'options' => ['is' => true]])] protected bool $mustBeTrue = false;
Having the
$mustBeTruein a fluid form as property for a checkbox field will always lead to a validation error, when the checkbox is not checked, because the property mapper will map the empty/non provided checkbox value to the default of the domain model/dto (in this casefalse).Therefore, I think we should not change the behavior of the
BooleanValidator, since this is highly breaking. Additionally the class comment also states, that the validator is intended for “boolean values”, so providing an empty string to it is not a supported scenario. -
Georg Ringer commented and changed status
NewClosed <span data-processor="relativetime" data-value="2026-02-06T18:31:17+00:00" > 02/06/26, 18:31 </span>closing, see comments of torben
IMO you would need the
conjunctionvalidatoror add an required validator to have bothhttps://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Validation/Validators/Index.html#conjunctionvalidator.
I don’t see this as bug. what do you think?