Project

General

Profile

Bug #24966 » resolveBackPath-regex.diff

Administrator Admin, 2011-02-05 23:00

View differences:

t3lib/class.t3lib_div.php (Arbeitskopie)
* @param string File path in which "/../" is resolved
* @return string
*/
public static function resolveBackPath($pathStr) {
$parts = explode('/', $pathStr);
$output = array();
$c = 0;
foreach ($parts as $pV) {
if ($pV == '..') {
if ($c) {
array_pop($output);
$c--;
} else {
$output[] = $pV;
}
} else {
$c++;
$output[] = $pV;
}
public static function resolveBackPath($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 /.. followed by (/ or end of path)
$path = preg_replace('#[^/\.]+/\.\.[/\Z]#iS', '', $path, -1, $count);
}
return implode('/', $output);
/*if (!$returnTrailingSlash && substr($path, -1) === '/') {
// no trailing slash is expected by the caller, so remove it
$path = substr($path, 0, -1);
}*/
return $path;
}
/**
(1-1/2)