Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Fixed set "empty_data" option with empty string to return empty string not null #10126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
};
}

return function (FormInterface $form) {
return $form->getConfig()->getCompound() ? array() : '';
return function (FormInterface $form, $defaultValue = '') {
return $form->getConfig()->getCompound() ? array() : $defaultValue;
};
};

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ private function viewToNorm($value)
$transformers = $this->config->getViewTransformers();

if (!$transformers) {
return '' === $value ? null : $value;
return $value;
}

for ($i = count($transformers) - 1; $i >= 0; --$i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,22 @@ public function testSubmitAddsNoDefaultProtocolIfEmpty()

$form->submit('');

$this->assertNull($form->getData());
$this->assertSame('',$form->getData()); // the data given was empty string so we should compare it to empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEmpty() instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEmpty will allow a lot of values, while we really want to make sure here that the outcome is an empty string

$this->assertSame('', $form->getViewData());
}

public function testSubmitAddsNoDefaultProtocolIfNull()
{
$form = $this->factory->create('url', null, array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to fix indentation.

'default_protocol' => 'http',
));

$form->submit(null);

$this->assertNull($form->getData());
$this->assertSame('', $form->getViewData());
}

public function testSubmitAddsNoDefaultProtocolIfSetToNull()
{
$form = $this->factory->create('url', null, array(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.