Skip to content

[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

Conversation

galileo
Copy link

@galileo galileo commented Jan 24, 2014

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #5906
License MIT
Doc PR -

I see no reason to check here the empty string value and return this with null value. This is place where the param was manualy requested by the user with the "empty_value" option so when he given it, he must have a reason to force string not null, so if he want to return empty string there is no reason to convert it to null value.

I see also no changes that will be done in the future flow with the methods normToModel and normToView.

So I'm pretty sure that resolves that issue.

@peterrehm
Copy link
Contributor

@galileo This might be related to #9773. Please check if this might fix your use case already.

@@ -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

@webmozart
Copy link
Contributor

Thank you for your work on this! I added the new test for UrlType to #10647.

I'm afraid we can't change the return type of the UrlType when an empty string is submitted. Currently, the convention is to always convert empty strings to null.

The solution is to implement #5906 properly, but that's not that trivial. :(

@webmozart webmozart closed this Apr 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants