From fa9fb5c1ce12a0b577671d68864ebcc0c5217261 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 21 Mar 2015 19:32:08 +0100 Subject: [PATCH] Replace GET parameters when changed --- src/Symfony/Component/DomCrawler/Form.php | 15 ++++++++++++--- .../Component/DomCrawler/Tests/FormTest.php | 6 ++++++ 2 files changed, 18 insertions(+), 3 deletions(-) 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', '
',