Skip to content

Commit

Permalink
[Form] Filter arrays out of scalar form types
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 24, 2018
1 parent e4a7fd8 commit b7da2a5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
Expand Up @@ -129,6 +129,7 @@ public function configureOptions(OptionsResolver $resolver)
'entry_type' => $entryType,
'entry_options' => $entryOptions,
'delete_empty' => false,
'multiple' => true,
));

$resolver->setNormalizer('type', $typeNormalizer);
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Form/Form.php
Expand Up @@ -537,6 +537,9 @@ public function submit($submittedData, $clearMissing = true)
$submittedData = null;
} elseif (is_scalar($submittedData)) {
$submittedData = (string) $submittedData;
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) {
$submittedData = null;
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.');
}

$dispatcher = $this->config->getEventDispatcher();
Expand Down
Expand Up @@ -93,14 +93,6 @@ public function testThrowExceptionIfDefaultProtocolIsInvalid()
));
}

public function testSubmitWithNonStringDataDoesNotBreakTheFixUrlProtocolListener()
{
$form = $this->factory->create(static::TESTED_TYPE);
$form->submit(array('domain.com', 'www.domain.com'));

$this->assertSame(array('domain.com', 'www.domain.com'), $form->getData());
}

public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = 'http://empty')
{
$form = $this->factory->create(static::TESTED_TYPE, null, array(
Expand Down
Expand Up @@ -248,7 +248,7 @@ public function testDontValidateConstraintsIfNoValidationGroups()
->getForm();

// Launch transformer
$form->submit(array());
$form->submit('foo');

$this->expectNoValidate();

Expand Down

0 comments on commit b7da2a5

Please sign in to comment.