Skip to content
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

Form Validation of IntegerType is rounding bigint with no warning #30582

Closed
AdelBachene opened this issue Mar 15, 2019 · 6 comments
Closed

Form Validation of IntegerType is rounding bigint with no warning #30582

AdelBachene opened this issue Mar 15, 2019 · 6 comments

Comments

@AdelBachene
Copy link

Symfony version(s) affected: 4.x.x

Description
Whenever we try to validate a bigint with IntegerType the number will be rounded with no warning

How to reproduce

  1. In your entity add a field of type bigint
  /**
     * @ORM\Column(name="original_transaction_id", type="bigint", nullable=true)
     */
    private $originalTransactionId;
  1. define Form validation type:
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;

class CreateFormValidationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add("originalTransactionId", IntegerType::class, [
                "required" => true,
                "constraints" => [
                    new Assert\NotNull,
                ]
            ])
     }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            "csrf_protection" => false,
            "data_class" => MyEntity::class,
        ]);
    }
}
  1. While validating the field it will change the value from bigint to a rounded int
            $receiptFormType = CreateFormValidationType::class;
            $receiptForm = $this->formFactory->create($receiptFormType, $MyEntity, ['allow_extra_fields' => true]);
            $receiptForm->submit($data, true);

Additional context
I'm using this version of symfony form "symfony/form": "^4.2"

@xabbuh
Copy link
Member

xabbuh commented Mar 16, 2019

Which exact version of the Form component did you use when this happened? Which concrete values are not handled correctly? Is your PHP using 32 or 64 bits?

@AdelBachene
Copy link
Author

@xabbuh the version in my composer.lock is:

{
            "name": "symfony/form",
            "version": "v4.2.2",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/form.git",
                "reference": "3361332a168850dc8b3abd133553f66c0cb28b1c"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/form/zipball/3361332a168850dc8b3abd133553f66c0cb28b1c",
                "reference": "3361332a168850dc8b3abd133553f66c0cb28b1c",
                "shasum": ""
            },
            "require": {
                "php": "^7.1.3",
                "symfony/event-dispatcher": "~3.4|~4.0",
                "symfony/intl": "~3.4|~4.0",
                "symfony/options-resolver": "~4.2",
                "symfony/polyfill-ctype": "~1.8",
                "symfony/polyfill-mbstring": "~1.0",
                "symfony/property-access": "~3.4|~4.0"
            },
            "conflict": {
                "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
                "symfony/dependency-injection": "<3.4",
                "symfony/doctrine-bridge": "<3.4",
                "symfony/framework-bundle": "<3.4",
                "symfony/http-kernel": "<3.4",
                "symfony/translation": "<4.2",
                "symfony/twig-bridge": "<3.4.5|<4.0.5,>=4.0"
            },
            "require-dev": {
                "doctrine/collections": "~1.0",
                "symfony/config": "~3.4|~4.0",
                "symfony/console": "~3.4|~4.0",
                "symfony/dependency-injection": "~3.4|~4.0",
                "symfony/http-foundation": "~3.4|~4.0",
                "symfony/http-kernel": "~3.4|~4.0",
                "symfony/security-csrf": "~3.4|~4.0",
                "symfony/translation": "~4.2",
                "symfony/validator": "~3.4|~4.0",
                "symfony/var-dumper": "~3.4|~4.0"
            },
            "suggest": {
                "symfony/framework-bundle": "For templating with PHP.",
                "symfony/security-csrf": "For protecting forms against CSRF attacks.",
                "symfony/twig-bridge": "For templating with Twig.",
                "symfony/validator": "For form validation."
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "4.2-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Symfony\\Component\\Form\\": ""
                },
                "exclude-from-classmap": [
                    "/Tests/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Form Component",
            "homepage": "https://symfony.com",
            "time": "2019-01-05T16:37:49+00:00"
},

an example of the value that wasn't handled is: 1000000510149786.

I'm running this on Docker with the next php tag From php:7.2-fpm

@xabbuh
Copy link
Member

xabbuh commented Mar 18, 2019

Can you please try this with 4.2.4? This may be fixed by #30063 which was part of the 4.2.4 release.

@AdelBachene
Copy link
Author

@xabbuh Indeed the problem is fixed in version 4.2.4. Thanks

@xabbuh
Copy link
Member

xabbuh commented Mar 18, 2019

Cool, thank you for the confirmation. 👍 I am going to close here then.

@xabbuh xabbuh closed this as completed Mar 18, 2019
@rik702
Copy link

rik702 commented Jun 13, 2022

This still seems to happen for integers with more than 15 digits, I think because of the use of the php floor() and ceil() functions in the rounding.

Perhaps an extra option of intval() for the rounding_mode option would give folks the option to avoid using floor() or ceil() and so avoid the jump to floating point and back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants