8000 [Form] Filter arrays out of scalar form types · symfony/symfony@b7da2a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7da2a5

Browse files
[Form] Filter arrays out of scalar form types
1 parent e4a7fd8 commit b7da2a5

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public function configureOptions(OptionsResolver $resolver)
129129
'entry_type' => $entryType,
130130
8000 'entry_options' => $entryOptions,
131131
'delete_empty' => false,
132+
'multiple' => true,
132133
));
133134

134135
$resolver->setNormalizer('type', $typeNormalizer);

src/Symfony/Component/Form/Form.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ public function submit($submittedData, $clearMissing = true)
537537
$submittedData = null;
538538
} elseif (is_scalar($submittedData)) {
539539
$submittedData = (string) $submittedData;
540+
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) {
541+
$submittedData = null;
542+
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.');
540543
}
541544

542545
$dispatcher = $this->config->getEventDispatcher();

src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ public function testThrowExceptionIfDefaultProtocolIsInvalid()
9393
));
9494
}
9595

96-
public function testSubmitWithNonStringDataDoesNotBreakTheFixUrlProtocolListener()
97-
{
98-
$form = $this->factory->create(static::TESTED_TYPE);
99-
$form->submit(array('domain.com', 'www.domain.com'));
100-
101-
$this->assertSame(array('domain.com', 'www.domain.com'), $form->getData());
102-
}
103-
10496
public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = 'http://empty')
10597
{
10698
$form = $this->factory->create(static::TESTED_TYPE, null, array(

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function testDontValidateConstraintsIfNoValidationGroups()
248248
->getForm();
249249

250250
// Launch transformer
251-
$form->submit(array());
251+
$form->submit('foo');
252252

253253
$this->expectNoValidate();
254254

0 commit comments

Comments
 (0)
0