Skip to content
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

Fixes #4263: Fixes /*.php shows home page #4265

Merged
merged 2 commits into from
Feb 12, 2021
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
2 changes: 1 addition & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ protected function parseRequestURI(): string
if (isset($_SERVER['SCRIPT_NAME'][0]) && pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_EXTENSION) === 'php')
{
// strip the script name from the beginning of the URI
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0 && strpos($uri, '/index.php') === 0)
{
$uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME']));
}
Expand Down
28 changes: 28 additions & 0 deletions tests/system/HTTP/IncomingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,32 @@ public function testGetPostIndexNotExists()
$this->assertNull($this->request->getPostGet('gc'));
$this->assertNull($this->request->getGetPost('gc'));
}

public function providePathChecks()
{
return [
'not /index.php' => [
'/test.php',
'test.php',
],
'/index.php' => [
'/index.php',
'/',
],
];
}

/**
* @dataProvider providePathChecks
*/
public function testExtensionPHP($path, $detectPath)
{
$config = new App();
$config->baseURL = 'http://example.com/';

$_SERVER['REQUEST_URI'] = $path;
$_SERVER['SCRIPT_NAME'] = $path;
$request = new IncomingRequest($config, new URI($path), null, new UserAgent());
$this->assertEquals($detectPath, $request->detectPath());
}
}