diff options
author | Thomas Mueller <thomas.mueller@tmit.eu> | 2013-02-11 12:59:23 +0100 |
---|---|---|
committer | Thomas Mueller <thomas.mueller@tmit.eu> | 2013-02-11 12:59:23 +0100 |
commit | f223ab796b8b6da796321502e8eeffed81973629 (patch) | |
tree | 7a4674f4f6d4038fd34b83b5d038dc88758312a3 /lib/files/storage | |
parent | 8174e5faf18fcd762efce5ffdfabfa1102580dd5 (diff) | |
parent | 0708f4dec058e98f9d2163000847bf3bc3877faf (diff) | |
download | nextcloud-server-f223ab796b8b6da796321502e8eeffed81973629.tar.gz nextcloud-server-f223ab796b8b6da796321502e8eeffed81973629.zip |
Merge branch 'master' into mapped-storage-unit-testing-linux-master
Diffstat (limited to 'lib/files/storage')
-rw-r--r-- | lib/files/storage/common.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 591803f0440..ce9e7ead6d1 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -277,4 +277,27 @@ abstract class Common implements \OC\Files\Storage\Storage { return uniqid(); } } + + /** + * 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; + } + + $output = array(); + foreach (explode('/', $path) as $chunk) { + if ($chunk == '..') { + array_pop($output); + } else if ($chunk == '.') { + } else { + $output[] = $chunk; + } + } + return implode('/', $output); + } } |