Skip to content
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
83 changes: 0 additions & 83 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,51 +320,6 @@ protected function includeFile(string $file)
return false;
}

/**
* Check file path.
*
* Checks special characters that are illegal in filenames on certain
* operating systems and special characters requiring special escaping
* to manipulate at the command line. Replaces spaces and consecutive
* dashes with a single dash. Trim period, dash and underscore from beginning
* and end of filename.
*
* @return string The sanitized filename
*
* @deprecated No longer used. See https://github.com/codeigniter4/CodeIgniter4/issues/7055
*/
public function sanitizeFilename(string $filename): string
{
// Only allow characters deemed safe for POSIX portable filenames.
// Plus the forward slash for directory separators since this might be a path.
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278
// Modified to allow backslash and colons for on Windows machines.
$result = preg_match_all('/[^0-9\p{L}\s\/\-_.:\\\\]/u', $filename, $matches);

if ($result > 0) {
$chars = implode('', $matches[0]);

throw new InvalidArgumentException(
'The file path contains special characters "' . $chars
. '" that are not allowed: "' . $filename . '"',
);
}
if ($result === false) {
$message = preg_last_error_msg();

throw new RuntimeException($message . '. filename: "' . $filename . '"');
}

// Clean up our filename edges.
$cleanFilename = trim($filename, '.-_');

if ($filename !== $cleanFilename) {
throw new InvalidArgumentException('The characters ".-_" are not allowed in filename edges: "' . $filename . '"');
}

return $cleanFilename;
}

/**
* @param array{only?: list<string>, exclude?: list<string>} $composerPackages
*/
Expand Down Expand Up @@ -442,44 +397,6 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
$this->addNamespace($newPaths);
}

/**
* Locates autoload information from Composer, if available.
*
* @deprecated No longer used.
*
* @return void
*/
protected function discoverComposerNamespaces()
{
if (! is_file(COMPOSER_PATH)) {
return;
}

/**
* @var ClassLoader $composer
*/
$composer = include COMPOSER_PATH;
$paths = $composer->getPrefixesPsr4();
$classes = $composer->getClassMap();

unset($composer);

// Get rid of CodeIgniter so we don't have duplicates
if (isset($paths['CodeIgniter\\'])) {
unset($paths['CodeIgniter\\']);
}

$newPaths = [];

foreach ($paths as $key => $value) {
// Composer stores namespaces with trailing slash. We don't.
$newPaths[rtrim($key, '\\ ')] = $value;
}

$this->prefixes = array_merge($this->prefixes, $newPaths);
$this->classmap = array_merge($this->classmap, $classes);
}

/**
* Loads helpers
*/
Expand Down
49 changes: 0 additions & 49 deletions tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use App\Controllers\Home;
use Closure;
use CodeIgniter\Exceptions\ConfigException;
use CodeIgniter\Exceptions\InvalidArgumentException;
use CodeIgniter\Exceptions\RuntimeException;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\ReflectionHelper;
use Config\Autoload;
Expand Down Expand Up @@ -231,53 +229,6 @@ public function testloadClassNonNamespaced(): void
$this->assertFalse(($this->classLoader)('Modules'));
}

public function testSanitizationContailsSpecialChars(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'The file path contains special characters "${}!#" that are not allowed: "${../path}!#/to/some/file.php_"',
);

$test = '${../path}!#/to/some/file.php_';

$this->loader->sanitizeFilename($test);
}

public function testSanitizationFilenameEdges(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'The characters ".-_" are not allowed in filename edges: "/path/to/some/file.php_"',
);

$test = '/path/to/some/file.php_';

$this->loader->sanitizeFilename($test);
}

public function testSanitizationRegexError(): void
{
$this->expectException(RuntimeException::class);

$test = mb_convert_encoding('クラスファイル.php', 'EUC-JP', 'UTF-8');

$this->loader->sanitizeFilename($test);
}

public function testSanitizationAllowUnicodeChars(): void
{
$test = 'Ä/path/to/some/file.php';

$this->assertSame($test, $this->loader->sanitizeFilename($test));
}

public function testSanitizationAllowsWindowsFilepaths(): void
{
$test = 'C:\path\to\some/file.php';

$this->assertSame($test, $this->loader->sanitizeFilename($test));
}

public function testFindsComposerRoutes(): void
{
$config = new Autoload();
Expand Down
3 changes: 3 additions & 0 deletions user_guide_src/source/changelogs/v4.8.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Method Signature Changes
Removed Deprecated Items
========================

- **Autoloader:** Removed the following deprecated methods:
- ``CodeIgniter\Autoloader\Autoloader::sanitizeFileName()``
- ``CodeIgniter\Autoloader\Autoloader::discoverComposerNamespaces()``
- **Exceptions:** Removed the following properties and methods deprecated since v4.4.0:
- ``CodeIgniter\Debug\Exceptions::$ob_level``
- ``CodeIgniter\Debug\Exceptions::$viewPath``
Expand Down
Loading