Update lib/filestorage/common.php

Added function to clean a path
This commit is contained in:
hkjolhede 2013-01-26 19:44:09 +01:00
parent ab4d52e980
commit 2fa3efd697
1 changed files with 24 additions and 0 deletions

View File

@ -288,4 +288,28 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
public function getOwner($path) {
return OC_User::getUser();
}
/**
* clean a path, i.e. remove all redundant '.' and '..'
* making sure that it can't point to higher than '/'
* @param $path The path to clean
* @return string cleaned path
*/
public function cleanPath($path) {
if (strlen($path) == 0 or $path[0] != '/') {
$path = '/' . $path;
}
$chunks = explode('/', $path);
$output = array();
foreach ($chunks as $chunk) {
if ($chunk == '..') {
array_pop($output);
} else if ($chunk == '.') {
} else {
$output[] = $chunk;
}
}
return implode('/', $output);
}
}