bug #21968 Fixed pathinfo calculation for requests starting with a question mark. (syzygymsu)
This PR was squashed before being merged into the 2.7 branch (closes #21968).
Discussion
----------
Fixed pathinfo calculation for requests starting with a question mark.
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #21967
| License | MIT
| Doc PR |
With improper `strpos` result check calculated pathinfo for requests starting with '?' equals to request itself.
Correct pathinfo for those requests should be '/'.
Commits
-------
43297b45de
Fixed pathinfo calculation for requests starting with a question mark.
This commit is contained in:
commit
e8653b9964
@ -1774,6 +1774,9 @@ class Request
|
||||
|
||||
// Does the baseUrl have anything in common with the request_uri?
|
||||
$requestUri = $this->getRequestUri();
|
||||
if ($requestUri !== '' && $requestUri[0] !== '/') {
|
||||
$requestUri = '/'.$requestUri;
|
||||
}
|
||||
|
||||
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
|
||||
// full $baseUrl matches
|
||||
@ -1846,9 +1849,12 @@ class Request
|
||||
}
|
||||
|
||||
// Remove the query string from REQUEST_URI
|
||||
if ($pos = strpos($requestUri, '?')) {
|
||||
if (false !== $pos = strpos($requestUri, '?')) {
|
||||
$requestUri = substr($requestUri, 0, $pos);
|
||||
}
|
||||
if ($requestUri !== '' && $requestUri[0] !== '/') {
|
||||
$requestUri = '/'.$requestUri;
|
||||
}
|
||||
|
||||
$pathInfo = substr($requestUri, strlen($baseUrl));
|
||||
if (null !== $baseUrl && (false === $pathInfo || '' === $pathInfo)) {
|
||||
|
@ -1264,6 +1264,12 @@ class RequestTest extends TestCase
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$this->assertEquals('/path%20test/info', $request->getPathInfo());
|
||||
|
||||
$server = array();
|
||||
$server['REQUEST_URI'] = '?a=b';
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$this->assertEquals('/', $request->getPathInfo());
|
||||
}
|
||||
|
||||
public function testGetPreferredLanguage()
|
||||
@ -1992,6 +1998,61 @@ class RequestTest extends TestCase
|
||||
array('CONNECT', false),
|
||||
);
|
||||
}
|
||||
|
||||
public function nonstandardRequestsData()
|
||||
{
|
||||
return array(
|
||||
array('', '', '/', 'http://host:8080/', ''),
|
||||
array('/', '', '/', 'http://host:8080/', ''),
|
||||
|
||||
array('hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
|
||||
array('/hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
|
||||
|
||||
array('', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||
array('?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||
array('/?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||
|
||||
array('x', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||
array('x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||
array('/x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||
|
||||
array('hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
|
||||
array('/hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
|
||||
|
||||
array('hello/app.php/x', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||
array('hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||
array('/hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nonstandardRequestsData
|
||||
*/
|
||||
public function testNonstandardRequests($requestUri, $queryString, $expectedPathInfo, $expectedUri, $expectedBasePath = '', $expectedBaseUrl = null)
|
||||
{
|
||||
if (null === $expectedBaseUrl) {
|
||||
$expectedBaseUrl = $expectedBasePath;
|
||||
}
|
||||
|
||||
$server = array(
|
||||
'HTTP_HOST' => 'host:8080',
|
||||
'SERVER_PORT' => '8080',
|
||||
'QUERY_STRING' => $queryString,
|
||||
'PHP_SELF' => '/hello/app.php',
|
||||
'SCRIPT_FILENAME' => '/some/path/app.php',
|
||||
'REQUEST_URI' => $requestUri,
|
||||
);
|
||||
|
||||
$request = new Request(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$this->assertEquals($expectedPathInfo, $request->getPathInfo());
|
||||
$this->assertEquals($expectedUri, $request->getUri());
|
||||
$this->assertEquals($queryString, $request->getQueryString());
|
||||
$this->assertEquals(8080, $request->getPort());
|
||||
$this->assertEquals('host:8080', $request->getHttpHost());
|
||||
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl());
|
||||
$this->assertEquals($expectedBasePath, $request->getBasePath());
|
||||
}
|
||||
}
|
||||
|
||||
class RequestContentProxy extends Request
|
||||
|
@ -144,7 +144,7 @@ class HttpUtilsTest extends TestCase
|
||||
// Plus must not decoded to space
|
||||
$this->assertTrue($utils->checkRequestPath($this->getRequest('/foo+bar'), '/foo+bar'));
|
||||
// Checking unicode
|
||||
$this->assertTrue($utils->checkRequestPath($this->getRequest(urlencode('/вход')), '/вход'));
|
||||
$this->assertTrue($utils->checkRequestPath($this->getRequest('/'.urlencode('вход')), '/вход'));
|
||||
}
|
||||
|
||||
public function testCheckRequestPathWithUrlMatcherAndResourceNotFound()
|
||||
|
Reference in New Issue
Block a user