Skip to content

Commit c16bb52

Browse files
bug #37270 [FrameworkBundle] preserve dots in query-string when redirecting (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] preserve dots in query-string when redirecting | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #29664 | License | MIT | Doc PR | - Commits ------- fcc0e2c [FrameworkBundle] preserve dots in query-string when redirecting
2 parents 13d5e18 + fcc0e2c commit c16bb52

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

src/Symfony/Bundle/FrameworkBundle/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 {

src/Symfony/Bundle/FrameworkBundle/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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy