Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return early if path is root #26344

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down