diff --git a/Tests/InputFilterTest.php b/Tests/InputFilterTest.php index 2506aba8..31f61fba 100644 --- a/Tests/InputFilterTest.php +++ b/Tests/InputFilterTest.php @@ -474,6 +474,36 @@ public function casesGeneric() 'C:\Documents\Newsletters\Summer2018.pdf', 'From generic cases' ), + 'windows path with 2 times double separator' => array( + 'path', + 'C:\Documents\\Newsletters\\Summer2018.pdf', + 'C:\Documents\Newsletters\Summer2018.pdf', + 'From generic cases' + ), + 'windows path with 3 times double separator' => array( + 'path', + 'C:\\Documents\\Newsletters\\Summer2018.pdf', + 'C:\Documents\Newsletters\Summer2018.pdf', + 'From generic cases' + ), + 'windows path with /' => array( + 'path', + 'C:\\Documents\\Newsletters/tmp', + 'C:\Documents\Newsletters\tmp', + 'From generic cases' + ), + 'windows path with 2 times /' => array( + 'path', + 'C:\\Documents/Newsletters/tmp', + 'C:\Documents\Newsletters\tmp', + 'From generic cases' + ), + 'windows path with 3 times /' => array( + 'path', + 'C:/Documents/Newsletters/tmp', + 'C:\Documents\Newsletters\tmp', + 'From generic cases' + ), 'user_01' => array( 'username', '&r%e\'d', diff --git a/src/InputFilter.php b/src/InputFilter.php index 6623872c..3ca42019 100644 --- a/src/InputFilter.php +++ b/src/InputFilter.php @@ -1011,11 +1011,11 @@ private function cleanPath($source) return preg_replace('~/+~', '/', $source); } - $windowsPattern = '/^([A-Za-z]:\\\\)?[A-Za-z0-9_\/-]+[A-Za-z0-9_\.-]*(\\\\+[A-Za-z0-9_-]+[A-Za-z0-9_\.-]*)*$/'; + $windowsPattern = '/^([A-Za-z]:(\\\\|\/))?[A-Za-z0-9_-]+[A-Za-z0-9_\.-]*((\\\\|\/)+[A-Za-z0-9_-]+[A-Za-z0-9_\.-]*)*$/'; if (preg_match($windowsPattern, $source)) { - return preg_replace('~\\\\+~', '\\', $source); + return preg_replace('~(\\\\|\/)+~', '\\', $source); } return '';