Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@mattwells
Copy link

QA
Branch?2.3+
Bug fix?yes
New feature?no
BC breaks?no?
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRn/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:

<selectname="gender"><optionselected></option><option>Female</option><option>Male</option></select>

When theDomCrawler\Field::getValue() is called I was expect to get the value'' however I was actually getting'on'. This is caused by theDomCrawler\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.

@mattwellsmattwells changed the titleFix Dom Crawler select option with empty valueFix select option with empty valueApr 6, 2016
@mattwellsmattwells changed the titleFix select option with empty value[DomCrawler] Fix select option with empty valueApr 6, 2016
$node =$this->createSelectNodeWithEmptyOption(array('' =>true,'Female' =>false,'Male' =>false));
$field =newChoiceFormField($node);

$this->assertEmpty($field->getValue());
Copy link
Member

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());

Copy link
Author

Choose a reason for hiding this comment

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

Done

@mattwellsmattwellsforce-pushed thefix-domcrawler-empty-select-option branch fromfa78a95 to58276a2CompareApril 6, 2016 13:14
@xabbuh
Copy link
Member

👍

Status: Reviewed

@stof
Copy link
Member

stof commentedApr 7, 2016

Thanks for fixing this bug@mattwells.

mattwells reacted with laugh emoji

@stofstof merged commit58276a2 intosymfony:2.3Apr 7, 2016
stof added a commit that referenced this pull requestApr 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/aWhile 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
@mattwellsmattwells deleted the fix-domcrawler-empty-select-option branchApril 7, 2016 10:44
This was referencedApr 29, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@mattwells@xabbuh@stof@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp