Skip to content
Merged
30 changes: 30 additions & 0 deletions Tests/InputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'&<f>r%e\'d',
Expand Down
4 changes: 2 additions & 2 deletions src/InputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down