-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DomCrawler] Fix select option with empty value #18460
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$node = $this->createSelectNodeWithEmptyOption(array('' => true, 'Female' => false, 'Male' => false)); | ||
$field = new ChoiceFormField($node); | ||
|
||
$this->assertEmpty($field->getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be more explicit here:
$this->assertSame('', $field->getValue());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fa78a95
to
58276a2
Compare
👍 Status: Reviewed |
Thanks for fixing this bug @mattwells. |
stof
added a commit
that referenced
this pull request
Apr 7, 2016
This PR was merged into the 2.3 branch. Discussion ---------- [DomCrawler] Fix select option with empty value | Q | A | ------------- | --- | Branch? | 2.3+ | Bug fix? | yes | New feature? | no | BC breaks? | no? | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a While using the Laravel's testing suite which makes use of the Symfony DOM Crawler (v3.0.2). I have been populating a form with a select which has a value which can be an empty value. For example, with this select you can choose your gender or leave it empty if you don't want to specify: ```html <select name="gender"> <option selected></option> <option>Female</option> <option>Male</option> </select> ``` When the `DomCrawler\Field::getValue()` is called I was expect to get the value `''` however I was actually getting `'on'`. This is caused by the [DomCrawler\Field::buildOptionValue()](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php#L262-L271) sets the default value to 'on' when there is no value which makes sense for ratios and checkboxes but not for select. I have tracked this bug back to v2.3 but it is still present in v3, however, the default value was changed from '1' to 'on' in v2.5 which means that this patch will conflict when merging up the maintained versions. Commits ------- 58276a2 Fix Dom Crawler select option with empty value
This was referenced Apr 29, 2016
Merged
Merged
Merged
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While using the Laravel's testing suite which makes use of the Symfony DOM Crawler (v3.0.2). I have been populating a form with a select which has a value which can be an empty value.
For example, with this select you can choose your gender or leave it empty if you don't want to specify:
When the
DomCrawler\Field::getValue()
is called I was expect to get the value''
however I was actually getting'on'
. This is caused by the DomCrawler\Field::buildOptionValue() sets the default value to 'on' when there is no value which makes sense for ratios and checkboxes but not for select.I have tracked this bug back to v2.3 but it is still present in v3, however, the default value was changed from '1' to 'on' in v2.5 which means that this patch will conflict when merging up the maintained versions.