Skip to content

Commit 4533624

Browse files
[FrameworkBundle] preserve dots in query-string when redirecting
1 parent c60957b commit 4533624

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

Controller/RedirectController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public function urlRedirectAction(Request $request, $path, $permanent = false, $
128128
$scheme = $request->getScheme();
129129
}
130130

131-
$qs = $request->getQueryString();
132-
if ($qs) {
131+
if ($qs = $request->server->get('QUERY_STRING') ?: $request->getQueryString()) {
133132
if (false === strpos($path, '?')) {
134133
$qs = '?'.$qs;
135134
} else {

Tests/Controller/RedirectControllerTest.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ public function pathQueryParamsProvider()
220220
return [
221221
['http://www.example.com/base/redirect-path', '/redirect-path', ''],
222222
['http://www.example.com/base/redirect-path?foo=bar', '/redirect-path?foo=bar', ''],
223-
['http://www.example.com/base/redirect-path?foo=bar', '/redirect-path', 'foo=bar'],
224-
['http://www.example.com/base/redirect-path?foo=bar&abc=example', '/redirect-path?foo=bar', 'abc=example'],
225-
['http://www.example.com/base/redirect-path?foo=bar&abc=example&baz=def', '/redirect-path?foo=bar', 'abc=example&baz=def'],
223+
['http://www.example.com/base/redirect-path?f.o=bar', '/redirect-path', 'f.o=bar'],
224+
['http://www.example.com/base/redirect-path?f.o=bar&a.c=example', '/redirect-path?f.o=bar', 'a.c=example'],
225+
['http://www.example.com/base/redirect-path?f.o=bar&a.c=example&b.z=def', '/redirect-path?f.o=bar', 'a.c=example&b.z=def'],
226226
];
227227
}
228228

@@ -246,29 +246,20 @@ public function testPathQueryParams($expectedUrl, $path, $queryString)
246246

247247
private function createRequestObject($scheme, $host, $port, $baseUrl, $queryString = '')
248248
{
249-
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
250-
$request
251-
->expects($this->any())
252-
->method('getScheme')
253-
->willReturn($scheme);
254-
$request
255-
->expects($this->any())
256-
->method('getHost')
257-
->willReturn($host);
258-
$request
259-
->expects($this->any())
260-
->method('getPort')
261-
->willReturn($port);
262-
$request
263-
->expects($this->any())
264-
->method('getBaseUrl')
265-
->willReturn($baseUrl);
266-
$request
267-
->expects($this->any())
268-
->method('getQueryString')
269-
->willReturn($queryString);
270-
271-
return $request;
249+
if ('' !== $queryString) {
250+
parse_str($queryString, $query);
251+
} else {
252+
$query = [];
253+
}
254+
255+
return new Request($query, [], [], [], [], [
256+
'HTTPS' => 'https' === $scheme,
257+
'HTTP_HOST' => $host.($port ? ':'.$port : ''),
258+
'SERVER_PORT' => $port,
259+
'SCRIPT_FILENAME' => $baseUrl,
260+
'REQUEST_URI' => $baseUrl,
261+
'QUERY_STRING' => $queryString,
262+
]);
272263
}
273264

274265
private function createRedirectController($httpPort = null, $httpsPort = null)

0 commit comments

Comments
 (0)