Project

General

Profile

Actions

Bug #106304

open

Extbase IntegerConverter fails validation on float input resulting in wrong values

Added by Bastian Stargazer 11 days ago. Updated 10 days ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
Start date:
2025-03-04
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.3
Tags:
extbase, typeconverter
Complexity:
Is Regression:
Sprint Focus:

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);
}

Actions #1

Updated by Torben Hansen 11 days ago

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

Actions #2

Updated by Bastian Stargazer 10 days ago

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.

Actions

Also available in: Atom PDF