diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 6dea8cdd0163..5052a4083695 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -346,8 +346,6 @@ protected function requireFile($file) * 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 @@ public function sanitizeFilename(string $filename): string // 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, '.-_'); diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index ad5916fa0a72..9e0da8af7625 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -127,13 +127,20 @@ public function testLoadLegacy() 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)); } //-------------------------------------------------------------------- + + public function testSanitizationAllowsWindowsFilepaths() + { + $test = 'C:\path\to\some/file.php'; + $this->assertEquals($test, $this->loader->sanitizeFilename($test)); + } + //-------------------------------------------------------------------- }