Fixing filename sanitizer in Autoloader to allow Windows filepaths through. Fixes #12

This commit is contained in:
Lonnie Ezell 2016-03-17 21:51:17 -05:00
parent eac6a0ce34
commit c7bb307729
2 changed files with 10 additions and 4 deletions

View File

@ -346,8 +346,6 @@ class Autoloader
* dashes with a single dash. Trim period, dash and underscore from beginning
* and end of filename.
*
* @todo Move to a helper?
*
* @param string $filename
*
* @return string The sanitized filename
@ -358,7 +356,8 @@ class Autoloader
// 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
$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.
$filename = trim($filename, '.-_');

View File

@ -127,7 +127,7 @@ class AutoloaderTest extends \CIUnitTestCase
public function testSanitizationSimply()
{
$test = '${../path}!#:/to/some/file.php_';
$test = '${../path}!#/to/some/file.php_';
$expected = '/path/to/some/file.php';
$this->assertEquals($expected, $this->loader->sanitizeFilename($test));
@ -135,5 +135,12 @@ class AutoloaderTest extends \CIUnitTestCase
//--------------------------------------------------------------------
public function testSanitizationAllowsWindowsFilepaths()
{
$test = 'C:\path\to\some/file.php';
$this->assertEquals($test, $this->loader->sanitizeFilename($test));
}
//--------------------------------------------------------------------
}