From bb255c658641bf97e13aa3d142d8de6f12d428b3 Mon Sep 17 00:00:00 2001 From: J0WI Date: Sat, 27 Mar 2021 14:47:58 +0100 Subject: [PATCH] Return early if path is root Signed-off-by: J0WI --- lib/private/Files/Filesystem.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index bf94be273f273..217773051caeb 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -800,10 +800,6 @@ public static function hasUpdated($path, $time) { * @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 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol */ $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);