Skip to content

Commit 905bbbd

Browse files
committed
bug symfony#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 symfony#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 | symfony#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 symfony#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
2 parents 7a4fdf7 + f24a6dd commit 905bbbd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ protected function prepareBaseUrl()
17121712
return $prefix;
17131713
}
17141714

1715-
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl).'/')) {
1715+
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(dirname($baseUrl), '/').'/')) {
17161716
// directory portion of $baseUrl matches
17171717
return rtrim($prefix, '/');
17181718
}

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,26 @@ public function testGetBaseUrl($uri, $server, $expectedBaseUrl, $expectedPathInf
13201320
public function getBaseUrlData()
13211321
{
13221322
return array(
1323+
array(
1324+
'/fruit/strawberry/1234index.php/blah',
1325+
array(
1326+
'SCRIPT_FILENAME' => 'E:/Sites/cc-new/public_html/fruit/index.php',
1327+
'SCRIPT_NAME' => '/fruit/index.php',
1328+
'PHP_SELF' => '/fruit/index.php',
1329+
),
1330+
'/fruit',
1331+
'/strawberry/1234index.php/blah',
1332+
),
1333+
array(
1334+
'/fruit/strawberry/1234index.php/blah',
1335+
array(
1336+
'SCRIPT_FILENAME' => 'E:/Sites/cc-new/public_html/index.php',
1337+
'SCRIPT_NAME' => '/index.php',
1338+
'PHP_SELF' => '/index.php',
1339+
),
1340+
'',
1341+
'/fruit/strawberry/1234index.php/blah',
1342+
),
13231343
array(
13241344
'/foo%20bar/',
13251345
array(

0 commit comments

Comments
 (0)