Return early if path is root

Signed-off-by: J0WI <J0WI@users.noreply.github.com>
This commit is contained in:
J0WI 2021-03-27 14:47:58 +01:00
parent bfd926938f
commit 0c9b8ad051

View file

@ -800,10 +800,6 @@ class Filesystem {
* @return string
*/
public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) {
if (is_null(self::$normalizedPathCache)) {
self::$normalizedPathCache = new CappedMemoryCache(2048);
}
/**
* FIXME: This is a workaround for existing classes and files which call
* this function with another type than a valid string. This
@ -812,16 +808,20 @@ class Filesystem {
*/
$path = (string)$path;
if ($path === '') {
return '/';
}
if (is_null(self::$normalizedPathCache)) {
self::$normalizedPathCache = new CappedMemoryCache(2048);
}
$cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath, $keepUnicode]);
if ($cacheKey && isset(self::$normalizedPathCache[$cacheKey])) {
return self::$normalizedPathCache[$cacheKey];
}
if ($path === '') {
return '/';
}
//normalize unicode if possible
if (!$keepUnicode) {
$path = \OC_Util::normalizeUnicode($path);