Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-11-14 16:15:03 +0400
committerVincent Petry <pvince81@owncloud.com>2013-11-14 16:15:03 +0400
commitc06d8bb0071839480f9e458e58630ca0c205b9cb (patch)
tree7d5114f0a80e5bbc3e5bd5b8e69a0da7c1af3a34 /lib
parent8d0d0836bae968d3abff5f5ff9db230d449397a6 (diff)
Fixed normalizePath() to strip out single dot dirs
Now removing "/./" and trailing "/." from the paths when normalizing.
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/filesystem.php20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 899666f3e1a..8500b3c581b 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -689,18 +689,32 @@ class Filesystem {
}
//no windows style slashes
$path = str_replace('\\', '/', $path);
+
//add leading slash
if ($path[0] !== '/') {
$path = '/' . $path;
}
- //remove duplicate slashes
- while (strpos($path, '//') !== false) {
- $path = str_replace('//', '/', $path);
+
+ // remove '/./'
+ // ugly, but str_replace() can't replace them all in one go
+ // as the replacement itself is part of the search string
+ // which will only be found during the next iteration
+ while (strpos($path, '/./') !== false) {
+ $path = str_replace('/./', '/', $path);
}
+ // remove sequences of slashes
+ $path = preg_replace('#/{2,}#', '/', $path);
+
//remove trailing slash
if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') {
$path = substr($path, 0, -1);
}
+
+ // remove trailing '/.'
+ if (substr($path, -2) == '/.') {
+ $path = substr($path, 0, -2);
+ }
+
//normalize unicode if possible
$path = \OC_Util::normalizeUnicode($path);