bug #10808 [DomCrawler] Empty select with attribute name="foo[]" bug fix (darles)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #10808).

Discussion
----------

[DomCrawler] Empty select with attribute name="foo[]" bug fix

If you have a select with attribute name="foo[]", and you submit your form, http_build_query returns empty string as a result. In this case you get a form extra field validation error, because your field "foo" converts to
'' => bool(false)

Commits
-------

15f081d Empty select with attribute name="foo[]" bug fix
This commit is contained in:
Fabien Potencier 2014-06-06 07:26:43 +02:00
commit 297d6501d7

View File

@ -146,9 +146,11 @@ class Form extends Link implements \ArrayAccess
$values = array();
foreach ($this->getValues() as $name => $value) {
$qs = http_build_query(array($name => $value), '', '&');
parse_str($qs, $expandedValue);
$varName = substr($name, 0, strlen(key($expandedValue)));
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
if(!empty($qs)) {
parse_str($qs, $expandedValue);
$varName = substr($name, 0, strlen(key($expandedValue)));
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
}
}
return $values;
@ -169,9 +171,11 @@ class Form extends Link implements \ArrayAccess
$values = array();
foreach ($this->getFiles() as $name => $value) {
$qs = http_build_query(array($name => $value), '', '&');
parse_str($qs, $expandedValue);
$varName = substr($name, 0, strlen(key($expandedValue)));
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
if(!empty($qs)) {
parse_str($qs, $expandedValue);
$varName = substr($name, 0, strlen(key($expandedValue)));
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
}
}
return $values;