Przeglądaj źródła

Fix bug with drive names of different cases

Jordi Boggiano 13 lat temu
rodzic
commit
680db4d1da

+ 4 - 4
src/Composer/Downloader/Util/Filesystem.php

@@ -58,8 +58,8 @@ class Filesystem
         if (dirname($from) === dirname($to)) {
             return './'.basename($to);
         }
-        $from = rtrim(strtr($from, '\\', '/'), '/');
-        $to = rtrim(strtr($to, '\\', '/'), '/');
+        $from = lcfirst(rtrim(strtr($from, '\\', '/'), '/'));
+        $to = lcfirst(rtrim(strtr($to, '\\', '/'), '/'));
 
         $commonPath = $to;
         while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {
@@ -93,8 +93,8 @@ class Filesystem
         if ($from === $to) {
             return $directories ? '__DIR__' : '__FILE__';
         }
-        $from = strtr($from, '\\', '/');
-        $to = strtr($to, '\\', '/');
+        $from = lcfirst(strtr($from, '\\', '/'));
+        $to = lcfirst(strtr($to, '\\', '/'));
 
         $commonPath = $to;
         while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {

+ 2 - 0
tests/Composer/Test/Downloader/Util/FilesystemTest.php

@@ -51,6 +51,7 @@ class FilesystemTest extends TestCase
             array('C:/Temp', 'C:\Temp\test', true, "__DIR__ . '/test'"),
             array('/tmp/test', '/tmp', true, "dirname(__DIR__)"),
             array('/tmp', '/tmp/test', true, "__DIR__ . '/test'"),
+            array('C:/Temp', 'c:\Temp\test', true, "__DIR__ . '/test'"),
         );
     }
 
@@ -81,6 +82,7 @@ class FilesystemTest extends TestCase
             array('/tmp/test/sub', '/tmp', "../"),
             array('/tmp', '/tmp/test', "test"),
             array('C:/Temp', 'C:\Temp\test', "test"),
+            array('C:/Temp', 'c:\Temp\test', "test"),
         );
     }
 }