aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
+ }
}