Skip to content

Commit fa9fb5c

Browse files
committed
Replace GET parameters when changed
1 parent d5a8a10 commit fa9fb5c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,18 @@ public function getUri()
197197
{
198198
$uri = parent::getUri();
199199

200-
if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH')) && $queryString = http_build_query($this->getValues(), null, '&')) {
201-
$sep = false === strpos($uri, '?') ? '?' : '&';
202-
$uri .= $sep.$queryString;
200+
if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) {
201+
$query = parse_url($uri, PHP_URL_QUERY);
202+
$currentParameters = array();
203+
if ($query) {
204+
parse_str($query, $currentParameters);
205+
}
206+
207+
$queryString = http_build_query(array_merge($currentParameters, $this->getValues()), null, '&');
208+
209+
$pos = strpos($uri, '?');
210+
$base = false === $pos ? $uri : substr($uri, 0, $pos);
211+
$uri = rtrim($base.'?'.$queryString, '?');
203212
}
204213

205214
return $uri;

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,12 @@ public function provideGetUriValues()
573573
array(),
574574
'/foo?bar=bar&foo=foo',
575575
),
576+
array(
577+
'replaces query values with the form values',
578+
'<form action="/foo?bar=bar"><input type="text" name="bar" value="foo" /><input type="submit" /></form>',
579+
array(),
580+
'/foo?bar=foo',
581+
),
576582
array(
577583
'returns an empty URI if the action is empty',
578584
'<form><input type="submit" /></form>',

0 commit comments

Comments
 (0)