/** * normalize the given path * * @param string $path * @return string */ public function normalize($path) { return trim(\OC_Util::normalizeUnicode($path), '/'); }
/** * normalize the given path * @param $path * @return string */ public function normalize($path) { return \OC_Util::normalizeUnicode($path); }
/** * Fix common problems with a file path * * @param string $path * @param bool $stripTrailingSlash whether to strip the trailing slash * @param bool $isAbsolutePath whether the given path is absolute * @param bool $keepUnicode true to disable unicode normalization * @return string */ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) { if (is_null(self::$normalizedPathCache)) { self::$normalizedPathCache = new CappedMemoryCache(); } /** * FIXME: This is a workaround for existing classes and files which call * this function with another type than a valid string. This * conversion should get removed as soon as all existing * function calls have been fixed. */ $path = (string) $path; $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath]); if (isset(self::$normalizedPathCache[$cacheKey])) { return self::$normalizedPathCache[$cacheKey]; } if ($path == '') { return '/'; } //normalize unicode if possible if (!$keepUnicode) { $path = \OC_Util::normalizeUnicode($path); } //no windows style slashes $path = str_replace('\\', '/', $path); //add leading slash if ($path[0] !== '/') { $path = '/' . $path; } // remove '/./' // ugly, but str_replace() can't replace them all in one go // as the replacement itself is part of the search string // which will only be found during the next iteration while (strpos($path, '/./') !== false) { $path = str_replace('/./', '/', $path); } // remove sequences of slashes $path = preg_replace('#/{2,}#', '/', $path); //remove trailing slash if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { $path = substr($path, 0, -1); } // remove trailing '/.' if (substr($path, -2) == '/.') { $path = substr($path, 0, -2); } $normalizedPath = $path; self::$normalizedPathCache[$cacheKey] = $normalizedPath; return $normalizedPath; }
/** * Fix common problems with a file path * * @param string $path * @param bool $stripTrailingSlash * @param bool $isAbsolutePath * @return string */ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) { /** * FIXME: This is a workaround for existing classes and files which call * this function with another type than a valid string. This * conversion should get removed as soon as all existing * function calls have been fixed. */ $path = (string) $path; $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath]); if (isset(self::$normalizedPathCache[$cacheKey])) { return self::$normalizedPathCache[$cacheKey]; } if ($path == '') { return '/'; } //normalize unicode if possible $path = \OC_Util::normalizeUnicode($path); //no windows style slashes $path = str_replace('\\', '/', $path); // When normalizing an absolute path, we need to ensure that the drive-letter // is still at the beginning on windows $windows_drive_letter = ''; if ($isAbsolutePath && \OC_Util::runningOnWindows() && preg_match('#^([a-zA-Z])$#', $path[0]) && $path[1] == ':' && $path[2] == '/') { $windows_drive_letter = substr($path, 0, 2); $path = substr($path, 2); } //add leading slash if ($path[0] !== '/') { $path = '/' . $path; } // remove '/./' // ugly, but str_replace() can't replace them all in one go // as the replacement itself is part of the search string // which will only be found during the next iteration while (strpos($path, '/./') !== false) { $path = str_replace('/./', '/', $path); } // remove sequences of slashes $path = preg_replace('#/{2,}#', '/', $path); //remove trailing slash if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { $path = substr($path, 0, -1); } // remove trailing '/.' if (substr($path, -2) == '/.') { $path = substr($path, 0, -2); } $normalizedPath = $windows_drive_letter . $path; self::$normalizedPathCache[$cacheKey] = $normalizedPath; return $normalizedPath; }
/** * Fix common problems with a file path * @param string $path * @param bool $stripTrailingSlash * @return string */ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) { if ($path == '') { return '/'; } //no windows style slashes $path = str_replace('\\', '/', $path); // When normalizing an absolute path, we need to ensure that the drive-letter // is still at the beginning on windows $windows_drive_letter = ''; if ($isAbsolutePath && \OC_Util::runningOnWindows() && preg_match('#^([a-zA-Z])$#', $path[0]) && $path[1] == ':' && $path[2] == '/') { $windows_drive_letter = substr($path, 0, 2); $path = substr($path, 2); } //add leading slash if ($path[0] !== '/') { $path = '/' . $path; } // remove '/./' // ugly, but str_replace() can't replace them all in one go // as the replacement itself is part of the search string // which will only be found during the next iteration while (strpos($path, '/./') !== false) { $path = str_replace('/./', '/', $path); } // remove sequences of slashes $path = preg_replace('#/{2,}#', '/', $path); //remove trailing slash if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { $path = substr($path, 0, -1); } // remove trailing '/.' if (substr($path, -2) == '/.') { $path = substr($path, 0, -2); } //normalize unicode if possible $path = \OC_Util::normalizeUnicode($path); return $windows_drive_letter . $path; }
/** * Fix common problems with a file path * @param string $path * @param bool $stripTrailingSlash * @return string */ public static function normalizePath($path, $stripTrailingSlash = true) { if ($path == '') { return '/'; } //no windows style slashes $path = str_replace('\\', '/', $path); //add leading slash if ($path[0] !== '/') { $path = '/' . $path; } // remove '/./' // ugly, but str_replace() can't replace them all in one go // as the replacement itself is part of the search string // which will only be found during the next iteration while (strpos($path, '/./') !== false) { $path = str_replace('/./', '/', $path); } // remove sequences of slashes $path = preg_replace('#/{2,}#', '/', $path); //remove trailing slash if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { $path = substr($path, 0, -1); } // remove trailing '/.' if (substr($path, -2) == '/.') { $path = substr($path, 0, -2); } //normalize unicode if possible $path = \OC_Util::normalizeUnicode($path); return $path; }
/** * @brief Fix common problems with a file path * @param string $path * @param bool $stripTrailingSlash * @return string */ public static function normalizePath($path, $stripTrailingSlash = true) { /** * FIXME: This is a workaround for existing classes and files which call * this function with another type than a valid string. This * conversion should get removed as soon as all existing * function calls have been fixed. */ $path = (string) $path; if ($path == '') { return '/'; } //normalize unicode if possible $path = \OC_Util::normalizeUnicode($path); //no windows style slashes $path = str_replace('\\', '/', $path); //add leading slash if ($path[0] !== '/') { $path = '/' . $path; } // remove '/./' // ugly, but str_replace() can't replace them all in one go // as the replacement itself is part of the search string // which will only be found during the next iteration while (strpos($path, '/./') !== false) { $path = str_replace('/./', '/', $path); } // remove sequences of slashes $path = preg_replace('#/{2,}#', '/', $path); //remove trailing slash if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { $path = substr($path, 0, -1); } // remove trailing '/.' if (substr($path, -2) == '/.') { $path = substr($path, 0, -2); } return $path; }