Update lib/filestorage/common.php
Added function to clean a path
This commit is contained in:
parent
ab4d52e980
commit
2fa3efd697
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue