8000 bug #38614 [HttpFoundation] Fix for virtualhosts based on URL path (m… · symfony/symfony@091265b · GitHub
[go: up one dir, main page]

Skip to content

Commit 091265b

Browse files
committed
bug #38614 [HttpFoundation] Fix for virtualhosts based on URL path (mvorisek)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Fix for virtualhosts based on URL path | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #34866 | License | MIT | Doc PR | no This PR fixes base URL detection when: - virtualhost is based on URL path - AND local path does not match that URL virtual host path prefix fix covered with tests Commits ------- 75ff868 [HttpFoundation] Fix for virtualhosts based on URL path
2 parents 1f46250 + 75ff868 commit 091265b

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,9 +1848,15 @@ protected function prepareBaseUrl()
18481848
}
18491849

18501850
$basename = basename($baseUrl);
1851-
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
1852-
// no match whatsoever; set it blank
1853-
return '';
1851+
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
1852+
// strip autoindex filename, for virtualhost based on URL path
1853+
$baseUrl = \dirname($baseUrl).'/';
1854+
1855+
$basename = basename($baseUrl);
1856+
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
1857+
// no match whatsoever; set it blank
1858+
return '';
1859+
}
18541860
}
18551861

18561862
// If using mod_rewrite or ISAPI_Rewrite strip the script filename

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,36 @@ public function getBaseUrlData()
17631763
'/foo',
17641764
'/bar+baz',
17651765
],
1766+
[
1767+
'/sub/foo/bar',
1768+
[
1769+
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app.php',
1770+
'SCRIPT_NAME' => '/foo/app.php',
1771+
'PHP_SELF' => '/foo/app.php',
1772+
],
1773+
'/sub/foo',
1774+
'/bar',
1775+
],
1776+
[
1777+
'/sub/foo/app.php/bar',
1778+
[
1779+
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app.php',
1780+
'SCRIPT_NAME' => '/foo/app.php',
1781+
'PHP_SELF' => '/foo/app.php',
1782+
],
1783+
'/sub/foo/app.php',
1784+
'/bar',
1785+
],
1786+
[
1787+
'/sub/foo/bar/baz',
1788+
[
1789+
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app2.phpx',
1790+
'SCRIPT_NAME' => '/foo/app2.phpx',
1791+
'PHP_SELF' => '/foo/app2.phpx',
1792+
],
1793+
'/sub/foo',
1794+
'/bar/baz',
1795+
],
17661796
];
17671797
}
17681798

0 commit comments

Comments
 (0)
0