mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Fixing filename sanitizer in Autoloader to allow Windows filepaths through. Fixes #12
This commit is contained in:
parent
eac6a0ce34
commit
c7bb307729
@ -346,8 +346,6 @@ class Autoloader
|
|||||||
* dashes with a single dash. Trim period, dash and underscore from beginning
|
* dashes with a single dash. Trim period, dash and underscore from beginning
|
||||||
* and end of filename.
|
* and end of filename.
|
||||||
*
|
*
|
||||||
* @todo Move to a helper?
|
|
||||||
*
|
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
*
|
*
|
||||||
* @return string The sanitized filename
|
* @return string The sanitized filename
|
||||||
@ -358,7 +356,8 @@ class Autoloader
|
|||||||
// Plus the forward slash for directory separators since this might
|
// Plus the forward slash for directory separators since this might
|
||||||
// be a path.
|
// be a path.
|
||||||
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278
|
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278
|
||||||
$filename = preg_replace('/[^a-zA-Z0-9\s\/\-\_\.]/', '', $filename);
|
// Modified to allow backslash and colons for on Windows machines.
|
||||||
|
$filename = preg_replace('/[^a-zA-Z0-9\s\/\-\_\.\:\\\\]/', '', $filename);
|
||||||
|
|
||||||
// Clean up our filename edges.
|
// Clean up our filename edges.
|
||||||
$filename = trim($filename, '.-_');
|
$filename = trim($filename, '.-_');
|
||||||
|
@ -127,13 +127,20 @@ class AutoloaderTest extends \CIUnitTestCase
|
|||||||
|
|
||||||
public function testSanitizationSimply()
|
public function testSanitizationSimply()
|
||||||
{
|
{
|
||||||
$test = '${../path}!#:/to/some/file.php_';
|
$test = '${../path}!#/to/some/file.php_';
|
||||||
$expected = '/path/to/some/file.php';
|
$expected = '/path/to/some/file.php';
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->loader->sanitizeFilename($test));
|
$this->assertEquals($expected, $this->loader->sanitizeFilename($test));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function testSanitizationAllowsWindowsFilepaths()
|
||||||
|
{
|
||||||
|
$test = 'C:\path\to\some/file.php';
|
||||||
|
|
||||||
|
$this->assertEquals($test, $this->loader->sanitizeFilename($test));
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user