Skip to content

Commit

Permalink
[HttpFoundation] Fix for virtualhosts based on URL path
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored and nicolas-grekas committed Nov 3, 2020
1 parent 889007a commit 9eeb37e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1848,9 +1848,15 @@ protected function prepareBaseUrl()
}

$basename = basename($baseUrl);
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
// no match whatsoever; set it blank
return '';
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
// strip autoindex filename, for virtualhost based on URL path
$baseUrl = \dirname($baseUrl).'/';

$basename = basename($baseUrl);
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
// no match whatsoever; set it blank
return '';
}
}

// If using mod_rewrite or ISAPI_Rewrite strip the script filename
Expand Down
30 changes: 30 additions & 0 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,36 @@ public function getBaseUrlData()
'/foo',
'/bar+baz',
],
[
'/sub/foo/bar',
[
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app.php',
'SCRIPT_NAME' => '/foo/app.php',
'PHP_SELF' => '/foo/app.php',
],
'/sub/foo',
'/bar',
],
[
'/sub/foo/app.php/bar',
[
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app.php',
'SCRIPT_NAME' => '/foo/app.php',
'PHP_SELF' => '/foo/app.php',
],
'/sub/foo/app.php',
'/bar',
],
[
'/sub/foo/bar/baz',
[
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app2.phpx',
'SCRIPT_NAME' => '/foo/app2.phpx',
'PHP_SELF' => '/foo/app2.phpx',
],
'/sub/foo',
'/bar/baz',
],
];
}

Expand Down

0 comments on commit 9eeb37e

Please sign in to comment.