Fixed wrong redirect url if path contains some query parameters
This commit is contained in:
parent
8fef4f0398
commit
a25d1e1c0f
@ -100,7 +100,11 @@ class RedirectController extends ContainerAware
|
||||
|
||||
$qs = $request->getQueryString();
|
||||
if ($qs) {
|
||||
if (strpos($path, '?') === false) {
|
||||
$qs = '?'.$qs;
|
||||
} else {
|
||||
$qs = '&'.$qs;
|
||||
}
|
||||
}
|
||||
|
||||
$port = '';
|
||||
|
@ -199,7 +199,36 @@ class RedirectControllerTest extends TestCase
|
||||
$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
|
||||
@ -218,6 +247,10 @@ class RedirectControllerTest extends TestCase
|
||||
->expects($this->any())
|
||||
->method('getBaseUrl')
|
||||
->will($this->returnValue($baseUrl));
|
||||
$request
|
||||
->expects($this->any())
|
||||
->method('getQueryString')
|
||||
->will($this->returnValue($queryString));
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
Reference in New Issue
Block a user