Issue Bug Closed

#106304Extbase IntegerConverter fails validation on float input resulting in wrong values

Bastian Stargazer 03/05/25, 00:00 updated 05/30/25, 14:48

Description

In a domain model, I have an attribute “size” where the user should enter its body-size in cm, e.g. 179.

The model attribute is defined as protected int $size = 0;

If the user enters “1,79”, the \TYPO3\CMS\Extbase\Property\TypeConverter\IntegerConverter throws the error “1,79” is no integer, which is right (Btw: this message is not translatable)

But if the user enters “ 1.79 “, the value passes the check and is saved as value “1” in the database!

The reason is, that “1.79” as float value passes the is_numeric($source) check (failure 1) and even worse, its casted to int in return (int)$source resulting in the wrong value (failure 2).

I can’t see an easy fix here, because is_integer() can’t be used (it failed in multiple other places).

*Current workaround:*
In my case I can just replace the dot “.” for the “size” argument and write it back to the request in inside the controller’s initializeAction():

public function initializeExampleAction(): void
{
    $arguments = $this->request->getArguments();
    $arguments['user']['size'] = str_replace('.', '', $arguments['user']['size'] ?? '');
    $this->request = $this->request->withArguments($arguments);
}

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Files 1

History 5

  1. Torben Hansen commented <span data-processor="relativetime" data-value="2025-03-05T10:32:24+00:00" > 03/05/25, 10:32 </span>

    Do you use any validators for the property $size? If not, you could try to use the IntegerValidator for the property.

  2. Bastian Stargazer commented <span data-processor="relativetime" data-value="2025-03-05T12:54:21+00:00" > 03/05/25, 12:54 </span>

    No, there was no additional validator set for this property, because I thought, just set the type to “int” is enough to make sure only int values are accepted.

    I just tried it, but it still fails because the IntegerConverter is executed first. So the input value of “1.79” is converted to 1, which is than validated by IntegerValidator as valid.

  3. Sébastien Delcroix commented <span data-processor="relativetime" data-value="2025-04-09T23:36:08+00:00" > 04/09/25, 23:36 </span>

    @stargazer

    Why is_int() could not be used ?

  4. Bastian Stargazer commented and changed attached issue-106304-example.png <span data-processor="relativetime" data-value="2025-04-10T08:03:55+00:00" > 04/10/25, 08:03 </span>

    @sdelcroix
    I don’t know, I just tried it and suddenly the applications starts failing on multiple other places, e.g. everywhere where a plain integer-value, ID or UID should be given to a model property.

    You can try it yourself if you replace is_numeric() with is_int() in \TYPO3\CMS\Extbase\Property\TypeConverter\IntegerConverter (line 59) and submit a custom Extbase frontend form.

    In the following example, an insurance UID from a select-box should be written as int to the model. The model attribute is defined as protected int $insuranceUid = 0; (We do NOT use the Extbase model type Insurance for this attribute here on purpose!).

    With the suggested change, suddenly field validation complains: “14” is no integer (see screenshot).

  5. Stefan Froemken commented and changed status New Closed assigned to Stefan Froemken <span data-processor="relativetime" data-value="2025-05-30T14:48:30+00:00" > 05/30/25, 14:48 </span>

    Hi Bastian,

    TYPO3 Extbase does not automatically handle locale-specific number formats like 12,4 (common in German), as it expects normalized input (e.g. 12.4). Handling such conversions should be done either on the frontend (e.g. via input validation or JS transformation) or in the controller using one of the initializeActions or custom converters. This keeps the framework locale-independent and avoids incorrect assumptions in multilingual environments.