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-15 13:39:43 +0400
commite44831d10f47e409623f2213488cac72915ffb69 (patch)
tree69bdec11e04616714590f2687b5b90c70ab29ae2 /lib
parent5aabf3826a6d58c8e30b6fd188d8357cc43135aa (diff)
Fixed normalizePath() to strip out single dot dirs
Now removing "/./" and trailing "/." from the paths when normalizing. Backport of c06d8bb0071839480f9e458e58630ca0c205b9cb
Diffstat (limited to 'lib')
-rw-r--r--lib/files/filesystem.php20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index 14ca882982e..1850d50f971 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -589,18 +589,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);
return $path;