Skip to content

[HttpFoundation] Fix for virtualhosts based on URL path #38614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Symfony/Component/HttpFoundation/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 src/Symfony/Component/HttpFoundation/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