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

Normalize dir separator of Exceptions::cleanPath and added more paths to clean #2847

Merged
merged 5 commits into from
Apr 20, 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
23 changes: 13 additions & 10 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,20 @@ protected function determineCodes(Throwable $exception): array
*/
public static function cleanPath(string $file): string
{
if (strpos($file, APPPATH) === 0)
switch (true)
{
$file = 'APPPATH/' . substr($file, strlen(APPPATH));
}
elseif (strpos($file, SYSTEMPATH) === 0)
{
$file = 'SYSTEMPATH/' . substr($file, strlen(SYSTEMPATH));
}
elseif (strpos($file, FCPATH) === 0)
{
$file = 'FCPATH/' . substr($file, strlen(FCPATH));
case strpos($file, APPPATH) === 0:
$file = 'APPPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(APPPATH));
break;
case strpos($file, SYSTEMPATH) === 0:
$file = 'SYSTEMPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(SYSTEMPATH));
break;
case strpos($file, FCPATH) === 0:
$file = 'FCPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(FCPATH));
break;
case defined('VENDORPATH') && strpos($file, VENDORPATH) === 0;
$file = 'VENDORPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(VENDORPATH));
break;
}

return $file;
Expand Down
1 change: 1 addition & 0 deletions system/Test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
defined('TESTPATH') || define('TESTPATH', realpath(HOMEPATH . 'tests/') . DIRECTORY_SEPARATOR);
defined('SUPPORTPATH') || define('SUPPORTPATH', realpath(TESTPATH . '_support/') . DIRECTORY_SEPARATOR);
defined('COMPOSER_PATH') || define('COMPOSER_PATH', realpath(HOMEPATH . 'vendor/autoload.php'));
defined('VENDORPATH') || define('VENDORPATH', realpath(HOMEPATH . 'vendor') . DIRECTORY_SEPARATOR);

// Load Common.php from App then System
if (file_exists(APPPATH . 'Common.php'))
Expand Down
10 changes: 10 additions & 0 deletions system/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ class_alias('Config\Services', 'CodeIgniter\Services');
// Now load Composer's if it's available
if (is_file(COMPOSER_PATH))
{
/**
* The path to the vendor directory.
*
* We do not want to enforce this, so set the constant if Composer was used.
*/
if (! defined('VENDORPATH'))
{
define('VENDORPATH', realpath(ROOTPATH . 'vendor') . DIRECTORY_SEPARATOR);
}

require_once COMPOSER_PATH;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/system/Debug/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,36 @@ public function testNew()
$actual = new Exceptions(new \Config\Exceptions(), \Config\Services::request(), \Config\Services::response());
$this->assertInstanceOf(Exceptions::class, $actual);
}

/**
* @dataProvider dirtyPathsProvider
*/
public function testCleanPaths($file, $expected)
{
$this->assertEquals($expected, Exceptions::cleanPath($file));
}

public function dirtyPathsProvider()
{
$ds = DIRECTORY_SEPARATOR;

return [
[
APPPATH . 'Config' . $ds . 'App.php',
'APPPATH' . $ds . 'Config' . $ds . 'App.php',
],
[
SYSTEMPATH . 'CodeIgniter.php',
'SYSTEMPATH' . $ds . 'CodeIgniter.php',
],
[
VENDORPATH . 'autoload.php',
'VENDORPATH' . $ds . 'autoload.php',
],
[
FCPATH . 'index.php',
'FCPATH' . $ds . 'index.php',
],
];
}
}