Issue Bug Closed

#106443BooleanValidator should interpret empty string as `false` But does not deal with empty values.

Lina Wolf 03/27/25, 06:30 updated 02/06/26, 18:31

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

  1. Georg Ringer commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2025-04-16T14:49:14+00:00" > 04/16/25, 14:49 </span>

    IMO you would need the conjunctionvalidator or add an required validator to have both

    https://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?

  2. 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.

  3. 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 boolean property 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 $mustBeTrue in 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 case false).

    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.

  4. Georg Ringer commented and changed status New Closed <span data-processor="relativetime" data-value="2026-02-06T18:31:17+00:00" > 02/06/26, 18:31 </span>

    closing, see comments of torben