bug #14335 [HttpFoundation] Fix baseUrl when script filename is contained in pathInfo (danez)
This PR was squashed before being merged into the 2.3 branch (closes #14335).
Discussion
----------
[HttpFoundation] Fix baseUrl when script filename is contained in pathInfo
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #13617
| License | MIT
| Doc PR |
When the script filename is just /index.php, dirname() returns '/' for it. In Request::prepareBaseUrl() we append '/' to it (as introduced in #13039), which is wrong in this scenario as the resulting string is '//'.
When we rtrim('/') the output of dirname() then '/' would be constructed in this case, and in all other cases it makes no difference as dirname() already trims the right forward slash if there are path segments.
The test-cases should clarify the exact scenario.
Commits
-------
f24a6dd
[HttpFoundation] Fix baseUrl when script filename is contained in pathInfo
This commit is contained in:
commit
905bbbdd90
|
@ -1712,7 +1712,7 @@ class Request
|
|||
return $prefix;
|
||||
}
|
||||
|
||||
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl).'/')) {
|
||||
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(dirname($baseUrl), '/').'/')) {
|
||||
// directory portion of $baseUrl matches
|
||||
return rtrim($prefix, '/');
|
||||
}
|
||||
|
|
|
@ -1320,6 +1320,26 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||
public function getBaseUrlData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'/fruit/strawberry/1234index.php/blah',
|
||||
array(
|
||||
'SCRIPT_FILENAME' => 'E:/Sites/cc-new/public_html/fruit/index.php',
|
||||
'SCRIPT_NAME' => '/fruit/index.php',
|
||||
'PHP_SELF' => '/fruit/index.php',
|
||||
),
|
||||
'/fruit',
|
||||
'/strawberry/1234index.php/blah',
|
||||
),
|
||||
array(
|
||||
'/fruit/strawberry/1234index.php/blah',
|
||||
array(
|
||||
'SCRIPT_FILENAME' => 'E:/Sites/cc-new/public_html/index.php',
|
||||
'SCRIPT_NAME' => '/index.php',
|
||||
'PHP_SELF' => '/index.php',
|
||||
),
|
||||
'',
|
||||
'/fruit/strawberry/1234index.php/blah',
|
||||
),
|
||||
array(
|
||||
'/foo%20bar/',
|
||||
array(
|
||||
|
|
Reference in New Issue