diff options
author | hkjolhede <hkjolhede@gmail.com> | 2013-01-26 19:44:09 +0100 |
---|---|---|
committer | hkjolhede <hkjolhede@gmail.com> | 2013-01-26 19:44:09 +0100 |
commit | 2fa3efd697833664cfa91d61dbd83cbd49a46417 (patch) | |
tree | f617b8a07763408a12a5effbaba9cb407269dc77 | |
parent | ab4d52e9802a9710a04c32574f1521880c0d74e4 (diff) | |
download | nextcloud-server-2fa3efd697833664cfa91d61dbd83cbd49a46417.tar.gz nextcloud-server-2fa3efd697833664cfa91d61dbd83cbd49a46417.zip |
Update lib/filestorage/common.php
Added function to clean a path
-rw-r--r-- | lib/filestorage/common.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index b97eb79d8d4..7a9e8b8944e 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -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); + } } |