8000 Merge branch '2.7' into 2.8 · symfony/symfony@4665cb9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4665cb9

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Fixed pathinfo calculation for requests starting with a question mark. [Security] simplify the SwitchUserListenerTest
2 parents cb51396 + 742db41 commit 4665cb9

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

Request.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,9 @@ protected function prepareBaseUrl()
17531753

17541754
// Does the baseUrl have anything in common with the request_uri?
17551755
$requestUri = $this->getRequestUri();
1756+
if ($requestUri !== '' && $requestUri[0] !== '/') {
1757+
$requestUri = '/'.$requestUri;
1758+
}
17561759

17571760
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
17581761
// full $baseUrl matches
@@ -1825,9 +1828,12 @@ protected function preparePathInfo()
18251828
}
18261829

18271830
// Remove the query string from REQUEST_URI
1828-
if ($pos = strpos($requestUri, '?')) {
1831+
if (false !== $pos = strpos($requestUri, '?')) {
18291832
$requestUri = substr($requestUri, 0, $pos);
18301833
}
1834+
if ($requestUri !== '' && $requestUri[0] !== '/') {
1835+
$requestUri = '/'.$requestUri;
1836+
}
18311837

18321838
$pathInfo = substr($requestUri, strlen($baseUrl));
18331839
if (null !== $baseUrl && (false === $pathInfo || '' === $pathInfo)) {

Tests/RequestTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,12 @@ public function testGetPathInfo()
12641264
$request->initialize(array(), array(), array(), array(), array(), $server);
12651265

12661266
$this->assertEquals('/path%20test/info', $request->getPathInfo());
1267+
1268+
$server = array();
1269+
$server['REQUEST_URI'] = '?a=b';
1270+
$request->initialize(array(), array(), array(), array(), array(), $server);
1271+
1272+
$this->assertEquals('/', $request->getPathInfo());
12671273
}
12681274

12691275
public function testGetPreferredLanguage()
@@ -2041,6 +2047,61 @@ public function methodCacheableProvider()
20412047
array('CONNECT', false),
20422048
);
20432049
}
2050+
2051+
public function nonstandardRequestsData()
2052+
{
2053+
return array(
2054+
array('', '', '/', 'http://host:8080/', ''),
2055+
array('/', '', '/', 'http://host:8080/', ''),
2056+
2057+
array('hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
2058+
array('/hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
2059+
2060+
array('', 'a=b', '/', 'http://host:8080/?a=b'),
2061+
array('?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
2062+
array('/?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
2063+
2064+
array('x', 'a=b', '/x', 'http://host:8080/x?a=b'),
2065+
array('x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
2066+
array('/x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
2067+
2068+
array('hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
2069+
array('/hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
2070+
2071+
array('hello/app.php/x', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
2072+
array('hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
2073+
array('/hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
2074+
);
2075+
}
2076+
2077+
/**
2078+
* @dataProvider nonstandardRequestsData
2079+
*/
2080+
public function testNonstandardRequests($requestUri, $queryString, $expectedPathInfo, $expectedUri, $expectedBasePath = '', $expectedBaseUrl = null)
2081+
{
2082+
if (null === $expectedBaseUrl) {
2083+
$expectedBaseUrl = $expectedBasePath;
2084+
}
2085+
2086+
$server = array(
2087+
'HTTP_HOST' => 'host:8080',
2088+
'SERVER_PORT' => '8080',
2089+
'QUERY_STRING' => $queryString,
2090+
'PHP_SELF' => '/hello/app.php',
2091+
'SCRIPT_FILENAME' => '/some/path/app.php',
2092+
'REQUEST_URI' => $requestUri,
2093+
);
2094+
2095+
$request = new Request(array(), array(), array(), array(), array(), $server);
2096+
2097+
$this->assertEquals($expectedPathInfo, $request->getPathInfo());
2098+
$this->assertEquals($expectedUri, $request->getUri());
2099+
$this->assertEquals($queryString, $request->getQueryString());
2100+
$this->assertEquals(8080, $request->getPort());
2101+
$this->assertEquals('host:8080', $request->getHttpHost());
2102+
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl());
2103+
$this->assertEquals($expectedBasePath, $request->getBasePath());
2104+
}
20442105
}
20452106

20462107
class RequestContentProxy extends Request

0 commit comments

Comments
 (0)
0