From 15f081d80af6386500d181a5c78f038ebfdf7262 Mon Sep 17 00:00:00 2001 From: Darius Date: Tue, 29 Apr 2014 12:54:32 +0300 Subject: [PATCH] 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) --- src/Symfony/Component/DomCrawler/Form.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index c228b56195..717e426c1e 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -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;