From e961f570b1c746b390828e857714ef0d02a52c92 Mon Sep 17 00:00:00 2001 From: Robbert Klarenbeek Date: Mon, 3 Feb 2014 22:33:42 +0100 Subject: [PATCH] [DomCrawler] Fixed incorrect value name conversion in getPhpValues() and getPhpFiles() --- src/Symfony/Component/DomCrawler/Form.php | 18 ++++++++++++++---- .../Component/DomCrawler/Tests/FormTest.php | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index 2649d6d33b..ccbc0952a1 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -143,8 +143,13 @@ class Form extends Link implements \ArrayAccess */ public function getPhpValues() { - $qs = http_build_query($this->getValues(), '', '&'); - parse_str($qs, $values); + $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))); + } return $values; } @@ -161,8 +166,13 @@ class Form extends Link implements \ArrayAccess */ public function getPhpFiles() { - $qs = http_build_query($this->getFiles(), '', '&'); - parse_str($qs, $values); + $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))); + } return $values; } diff --git a/src/Symfony/Component/DomCrawler/Tests/FormTest.php b/src/Symfony/Component/DomCrawler/Tests/FormTest.php index 7acd36c675..888e74efb6 100644 --- a/src/Symfony/Component/DomCrawler/Tests/FormTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/FormTest.php @@ -391,6 +391,9 @@ class FormTest extends \PHPUnit_Framework_TestCase { $form = $this->createForm('
'); $this->assertEquals(array('foo' => array('bar' => 'foo'), 'bar' => 'bar'), $form->getPhpValues(), '->getPhpValues() converts keys with [] to arrays'); + + $form = $this->createForm('
'); + $this->assertEquals(array('fo.o' => array('ba.r' => 'foo'), 'ba r' => 'bar'), $form->getPhpValues(), '->getPhpValues() preserves periods and spaces in names'); } public function testGetFiles() @@ -418,6 +421,9 @@ class FormTest extends \PHPUnit_Framework_TestCase { $form = $this->createForm('
'); $this->assertEquals(array('foo' => array('bar' => array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0))), $form->getPhpFiles(), '->getPhpFiles() converts keys with [] to arrays'); + + $form = $this->createForm('
'); + $this->assertEquals(array('f.o o' => array('bar' => array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0))), $form->getPhpFiles(), '->getPhpFiles() preserves periods and spaces in names'); } /**