Skip to content

Commit 0477ff7

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: do not accept array input when a form is not multiple Update PR template
2 parents 2ec86df + b19668b commit 0477ff7

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public function submit($submittedData, bool $clearMissing = true)
546546
$submittedData = null;
547547
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');
548548
}
549-
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) {
549+
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->getOption('multiple', false)) {
550550
$submittedData = null;
551551
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.');
552552
}

Tests/CompoundFormTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,8 @@ public function testArrayTransformationFailureOnSubmit()
10571057
$this->assertNull($this->form->get('foo')->getData());
10581058
$this->assertSame('Submitted data was expected to be text or number, array given.', $this->form->get('foo')->getTransformationFailure()->getMessage());
10591059

1060-
$this->assertSame(['bar'], $this->form->get('bar')->getData());
1060+
$this->assertNull($this->form->get('bar')->getData());
1061+
$this->assertSame('Submitted data was expected to be text or number, array given.', $this->form->get('bar')->getTransformationFailure()->getMessage());
10611062
}
10621063

10631064
public function testFileUpload()

Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
1717
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
1818
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
19+
use Symfony\Component\Form\Exception\TransformationFailedException;
20+
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
1921
use Symfony\Component\Form\FormInterface;
2022
use Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory;
2123
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
@@ -1954,7 +1956,12 @@ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionDa
19541956

19551957
$form->submit($submissionData);
19561958
$this->assertFalse($form->isSynchronized());
1957-
$this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage());
1959+
$this->assertInstanceOf(TransformationFailedException::class, $form->getTransformationFailure());
1960+
if (!$multiple && !$expanded) {
1961+
$this->assertEquals('Submitted data was expected to be text or number, array given.', $form->getTransformationFailure()->getMessage());
1962+
} else {
1963+
$this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage());
1964+
}
19581965
}
19591966

19601967
public function invalidNestedValueTestMatrix()

0 commit comments

Comments
 (0)