Optimize loop
This commit is contained in:
parent
abacfd84da
commit
2f18a09a20
|
@ -494,17 +494,20 @@ abstract class Common implements \OC\Files\Storage\Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $fileName
|
* @param string $fileName
|
||||||
|
* @param string $invalidChars
|
||||||
* @throws InvalidPathException
|
* @throws InvalidPathException
|
||||||
*/
|
*/
|
||||||
private function scanForInvalidCharacters($fileName, $invalidChars) {
|
private function scanForInvalidCharacters($fileName, $invalidChars) {
|
||||||
foreach (str_split($fileName) as $char) {
|
foreach(str_split($invalidChars) as $char) {
|
||||||
if (strpos($invalidChars, $char) !== false) {
|
if (strpos($fileName, $char) !== false) {
|
||||||
throw new InvalidPathException('File name contains at least one invalid characters');
|
throw new InvalidPathException('File name contains at least one invalid characters');
|
||||||
}
|
}
|
||||||
if (ord($char) >= 0 && ord($char) <= 31) {
|
|
||||||
throw new InvalidPathException('File name contains at least one invalid characters');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sanitizedFileName = filter_var($fileName, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
|
||||||
|
if($sanitizedFileName !== $fileName) {
|
||||||
|
throw new InvalidPathException('File name contains at least one invalid characters');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue