summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhkjolhede <hkjolhede@gmail.com>2013-01-26 19:44:09 +0100
committerhkjolhede <hkjolhede@gmail.com>2013-01-26 19:44:09 +0100
commit2fa3efd697833664cfa91d61dbd83cbd49a46417 (patch)
treef617b8a07763408a12a5effbaba9cb407269dc77
parentab4d52e9802a9710a04c32574f1521880c0d74e4 (diff)
downloadnextcloud-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.php24
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);
+ }
}