Merge pull request #26344 from J0WI/fs-early-root

Return early if path is root
This commit is contained in:
Lukas Reschke 2021-06-23 15:21:56 +02:00 committed by GitHub
commit a70fd1bad1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -777,10 +777,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
@ -789,16 +785,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);