diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index 772b7f8bf6..b0462f098f 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -197,9 +197,18 @@ class Form extends Link implements \ArrayAccess { $uri = parent::getUri(); - if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH')) && $queryString = http_build_query($this->getValues(), null, '&')) { - $sep = false === strpos($uri, '?') ? '?' : '&'; - $uri .= $sep.$queryString; + if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { + $query = parse_url($uri, PHP_URL_QUERY); + $currentParameters = array(); + if ($query) { + parse_str($query, $currentParameters); + } + + $queryString = http_build_query(array_merge($currentParameters, $this->getValues()), null, '&'); + + $pos = strpos($uri, '?'); + $base = false === $pos ? $uri : substr($uri, 0, $pos); + $uri = rtrim($base.'?'.$queryString, '?'); } return $uri; diff --git a/src/Symfony/Component/DomCrawler/Tests/FormTest.php b/src/Symfony/Component/DomCrawler/Tests/FormTest.php index 1712dc2471..f12fcee86d 100644 --- a/src/Symfony/Component/DomCrawler/Tests/FormTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/FormTest.php @@ -573,6 +573,12 @@ class FormTest extends \PHPUnit_Framework_TestCase array(), '/foo?bar=bar&foo=foo', ), + array( + 'replaces query values with the form values', + '
', + array(), + '/foo?bar=foo', + ), array( 'returns an empty URI if the action is empty', '',