Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Feb 12, 2021
1 parent 8640252 commit 028bf32
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
14 changes: 8 additions & 6 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,15 @@ protected function parseRequestURI(): string

if (isset($_SERVER['SCRIPT_NAME'][0]) && pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_EXTENSION) === 'php')
{
// if index.php is implied
if (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
$uri = $uri === '/index.php'
? '/'
: (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
// strip the script name from the beginning of the URI
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
elseif (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
{
$uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME']));
}
Expand All @@ -728,11 +735,6 @@ protected function parseRequestURI(): string
{
$uri = (string) substr($uri, strpos($uri, $_SERVER['SCRIPT_NAME']) + strlen($_SERVER['SCRIPT_NAME']));
}
// or if index.php is implied
elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
$uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
}

// This section ensures that even on servers that require the URI to contain the query string (Nginx) a correct
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());
}
}

0 comments on commit 028bf32

Please sign in to comment.