Skip to content

Commit 1017571

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

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public function submit(mixed $submittedData, bool $clearMissing = true): static
507507
$submittedData = null;
508508
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');
509509
}
510-
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) {
510+
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->getOption('multiple', false)) {
511511
$submittedData = null;
512512
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.');
513513
}

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
1515
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
1616
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
17+
use Symfony\Component\Form\Exception\TransformationFailedException;
1718
use Symfony\Component\Form\FormInterface;
1819
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
1920

@@ -1949,7 +1950,12 @@ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionDa
19491950

19501951
$form->submit($submissionData);
19511952
$this->assertFalse($form->isSynchronized());
1952-
$this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage());
1953+
$this->assertInstanceOf(TransformationFailedException::class, $form->getTransformationFailure());
1954+
if (!$multiple && !$expanded) {
1955+
$this->assertEquals('Submitted data was expected to be text or number, array given.', $form->getTransformationFailure()->getMessage());
1956+
} else {
1957+
$this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage());
1958+
}
19531959
}
19541960

19551961
public function invalidNestedValueTestMatrix()

0 commit comments

Comments
 (0)