Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] RepeatedType with not mapped fields allows to have different values #36410

Closed
@biozshock

Description

@biozshock

Symfony version(s) affected: 3.4

Description
If one (or both) fields in RepeatedType is not mapped the form allows to have different values

How to reproduce
Add to Tests/Extension/Core/Type/RepeatedTypeTest.php

public function testSubmitUnequalNotMapped(): void
{
    $input = ['first' => 'foo', 'second' => 'bar'];

    $form = $this->factory->create(static::TESTED_TYPE, null, [
        'type' => TextTypeTest::TESTED_TYPE,
        'first_options' => ['mapped' => false],
        'second_options' => ['mapped' => false],
    ]);

    $form->submit($input);

    $this->assertSame('foo', $form['first']->getViewData());
    $this->assertSame('bar', $form['second']->getViewData());
    $this->assertFalse($form->isSynchronized());
    $this->assertSame($input, $form->getViewData());
    $this->assertNull($form->getData());
}

Happens because \Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer is called with value === null on unmapped field.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions