Project

General

Profile

Bug #24966 » resolveBackPath-comparison.diff

Administrator Admin, 2011-02-05 23:00

View differences:

t3lib/class.t3lib_div.php (Arbeitskopie)
return str_replace('//', '/', str_replace('\\', '/', $theFile));
}
public static function resolveBackPath($path) {
$explode = self::resolveBackPathExplode($path);
$preg = self::resolveBackPathPreg($path);
if ($explode !== $preg) {
throw new Exception("Explode and Preg don't match for input " . $path);
}
return $explode;
}
/**
* Resolves "../" sections in the input path string.
* For example "fileadmin/directory/../other_directory/" will be resolved to "fileadmin/other_directory/"
......
* @param string File path in which "/../" is resolved
* @return string
*/
public static function resolveBackPath($pathStr) {
public static function resolveBackPathExplode($pathStr) {
$parts = explode('/', $pathStr);
$output = array();
$c = 0;
......
return implode('/', $output);
}
public static function resolveBackPathPreg($path) {
/*$returnTrailingSlash = TRUE;
if (substr($path, -1) !== '/') {
// special case, if path lacks a trailing slash
$path .= '/';
$returnTrailingSlash = FALSE;
}*/
// go on with replacement, until nothing can be replaced anymore
$count = 1;
while ($count > 0) {
// search for (anything, but / or .) followed by /..
$path = preg_replace('#[^/\.]+/\.\./#iS', '', $path, -1, $count);
}
/*if (!$returnTrailingSlash && substr($path, -1) === '/') {
// no trailing slash is expected by the caller, so remove it
$path = substr($path, 0, -1);
}*/
return $path;
}
/**
* Prefixes a URL used with 'header-location' with 'http://...' depending on whether it has it already.
* - If already having a scheme, nothing is prepended
(2-2/2)