Skip to content

Commit

Permalink
Fixed wrong redirect url if path contains some query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
pulzarraider committed Feb 13, 2014
1 parent 8fef4f0 commit a25d1e1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Expand Up @@ -100,7 +100,11 @@ public function urlRedirectAction(Request $request, $path, $permanent = false, $

$qs = $request->getQueryString();
if ($qs) {
$qs = '?'.$qs;
if (strpos($path, '?') === false) {
$qs = '?'.$qs;
} else {
$qs = '&'.$qs;
}
}

$port = '';
Expand Down
Expand Up @@ -199,7 +199,36 @@ public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme,
$this->assertRedirectUrl($returnValue, $expectedUrl);
}

private function createRequestObject($scheme, $host, $port, $baseUrl)
public function pathQueryParamsProvider()
{
return array(
array('http://www.example.com/base/redirect-path', '/redirect-path', ''),
array('http://www.example.com/base/redirect-path?foo=bar', '/redirect-path?foo=bar', ''),
array('http://www.example.com/base/redirect-path?foo=bar', '/redirect-path', 'foo=bar'),
array('http://www.example.com/base/redirect-path?foo=bar&abc=example', '/redirect-path?foo=bar', 'abc=example'),
array('http://www.example.com/base/redirect-path?foo=bar&abc=example&baz=def', '/redirect-path?foo=bar', 'abc=example&baz=def'),
);
}

/**
* @dataProvider pathQueryParamsProvider
*/
public function testPathQueryParams($expectedUrl, $path, $queryString)
{
$scheme = 'http';
$host = 'www.example.com';
$baseUrl = '/base';
$port = 80;

$request = $this->createRequestObject($scheme, $host, $port, $baseUrl, $queryString);

$controller = $this->createRedirectController();

$returnValue = $controller->urlRedirectAction($request, $path, false, $scheme, $port, null);
$this->assertRedirectUrl($returnValue, $expectedUrl);
}

private function createRequestObject($scheme, $host, $port, $baseUrl, $queryString = '')
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request
Expand All @@ -218,6 +247,10 @@ private function createRequestObject($scheme, $host, $port, $baseUrl)
->expects($this->any())
->method('getBaseUrl')
->will($this->returnValue($baseUrl));
$request
->expects($this->any())
->method('getQueryString')
->will($this->returnValue($queryString));

return $request;
}
Expand Down

0 comments on commit a25d1e1

Please sign in to comment.