8000 Fix Dom Crawler select option with empty value · symfony/symfony@58276a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 58276a2

Browse files
author
Matt Wells
committed
Fix Dom Crawler select option with empty value
1 parent 192e821 commit 58276a2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ private function buildOptionValue($node)
259259
{
260260
$option = array();
261261

262-
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : '1';
262+
$defaultDefaultValue = 'select' === $this->node->nodeName ? '' : '1';
263+
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : $defaultDefaultValue;
263264
$option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue;
264265
$option['disabled'] = $node->hasAttribute('disabled');
265266

src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,14 @@ public function testOptionWithNoValue()
336336
$this->assertEquals('foo', $field->getValue(), '->select() changes the selected option');
337337
}
338338

339+
public function testSelectWithEmptyValue()
340+
{
341+
$node = $this->createSelectNodeWithEmptyOption(array('' => true, 'Female' => false, 'Male' => false));
342+
$field = new ChoiceFormField($node);
343+
344+
$this->assertSame('', $field->getValue());
345+
}
346+
339347
protected function createSelectNode($options, $attributes = array(), $selectedAttrText = 'selected')
340348
{
341349
$document = new \DOMDocument();

0 commit comments

Comments
 (0)
0