Skip to content

Commit

Permalink
bug #24573 [3.3] Fixed pathinfo calculation for requests starting wit…
Browse files Browse the repository at this point in the history
…h a question mark. (syzygymsu)

This PR was merged into the 3.3 branch.

Discussion
----------

[3.3] Fixed pathinfo calculation for requests starting with a question mark.

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24487
| License       | MIT
| Doc PR        | no

Fix of bad merge conflict resolving as mentioned in #24487. Port #21968 to 3.3+

Commits
-------

c17a922 Fixed pathinfo calculation for requests starting with a question mark.  - fix bad conflict resolving issue  - port #21968 to 3.3+
  • Loading branch information
fabpot committed Oct 16, 2017
2 parents ff4f4ca + c17a922 commit d32ecff
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1863,6 +1863,9 @@ protected function prepareBaseUrl()

// 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
Expand Down Expand Up @@ -1935,9 +1938,12 @@ protected function preparePathInfo()
}

// 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)) {
Expand Down
61 changes: 61 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -1286,6 +1286,12 @@ public function testGetPathInfo()
$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 testGetParameterPrecedence()
Expand Down Expand Up @@ -2188,6 +2194,61 @@ public function testGetTrustedHeaderName()
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_FORWARDED_PORT');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO');
}

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
Expand Down

0 comments on commit d32ecff

Please sign in to comment.