]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make it possible to cleanPath() absolute Windows paths
authorJoas Schilling <nickvergessen@gmx.de>
Fri, 7 Nov 2014 09:52:37 +0000 (10:52 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Mon, 17 Nov 2014 09:48:15 +0000 (10:48 +0100)
lib/private/files/filesystem.php

index c7dc99c55cb6fdf05cc8eea35535e7b2b85f7136..6c8fa8c90baf37d30ffb2ca5ec372ff74f28be47 100644 (file)
@@ -698,13 +698,22 @@ class Filesystem {
         * @param bool $stripTrailingSlash
         * @return string
         */
-       public static function normalizePath($path, $stripTrailingSlash = true) {
+       public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) {
                if ($path == '') {
                        return '/';
                }
+
                //no windows style slashes
                $path = str_replace('\\', '/', $path);
 
+               // When normalizing an absolute path, we need to ensure that the drive-letter
+               // is still at the beginning on windows
+               $windows_drive_letter = '';
+               if ($isAbsolutePath && \OC_Util::runningOnWindows() && preg_match('#^([a-zA-Z])$#', $path[0]) && $path[1] == ':' && $path[2] == '/') {
+                       $windows_drive_letter = substr($path, 0, 2);
+                       $path = substr($path, 2);
+               }
+
                //add leading slash
                if ($path[0] !== '/') {
                        $path = '/' . $path;
@@ -733,7 +742,7 @@ class Filesystem {
                //normalize unicode if possible
                $path = \OC_Util::normalizeUnicode($path);
 
-               return $path;
+               return $windows_drive_letter . $path;
        }
 
        /**