diff options
author | Vincent Petry <pvince81@owncloud.com> | 2013-11-14 13:15:03 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2013-11-14 13:15:03 +0100 |
commit | c06d8bb0071839480f9e458e58630ca0c205b9cb (patch) | |
tree | 7d5114f0a80e5bbc3e5bd5b8e69a0da7c1af3a34 /lib/private/files | |
parent | 8d0d0836bae968d3abff5f5ff9db230d449397a6 (diff) | |
download | nextcloud-server-c06d8bb0071839480f9e458e58630ca0c205b9cb.tar.gz nextcloud-server-c06d8bb0071839480f9e458e58630ca0c205b9cb.zip |
Fixed normalizePath() to strip out single dot dirs
Now removing "/./" and trailing "/." from the paths when normalizing.
Diffstat (limited to 'lib/private/files')
-rw-r--r-- | lib/private/files/filesystem.php | 20 |
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); |