Преглед изворни кода

Fix handling of paths on windows when cwd is root of drive, fixes #5554

Jordi Boggiano пре 8 година
родитељ
комит
ff7daf0bd4
2 измењених фајлова са 8 додато и 1 уклоњено
  1. 2 1
      src/Composer/Util/Filesystem.php
  2. 6 0
      tests/Composer/Test/Util/FilesystemTest.php

+ 2 - 1
src/Composer/Util/Filesystem.php

@@ -444,7 +444,8 @@ class Filesystem
         $prefix = '';
         $absolute = false;
 
-        if (preg_match('{^([0-9a-z]+:(?://(?:[a-z]:)?)?)}i', $path, $match)) {
+        // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive:
+        if (preg_match('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) {
             $prefix = $match[1];
             $path = substr($path, strlen($prefix));
         }

+ 6 - 0
tests/Composer/Test/Util/FilesystemTest.php

@@ -204,12 +204,18 @@ class FilesystemTest extends TestCase
             array('../foo', '../foo'),
             array('c:/foo/bar', 'c:/foo//bar'),
             array('C:/foo/bar', 'C:/foo/./bar'),
+            array('C:/foo/bar', 'C://foo//bar'),
+            array('C:/foo/bar', 'C:///foo//bar'),
             array('C:/bar', 'C:/foo/../bar'),
             array('/bar', '/foo/../bar/'),
             array('phar://c:/Foo', 'phar://c:/Foo/Bar/..'),
+            array('phar://c:/Foo', 'phar://c:///Foo/Bar/..'),
             array('phar://c:/', 'phar://c:/Foo/Bar/../../../..'),
             array('/', '/Foo/Bar/../../../..'),
             array('/', '/'),
+            array('/', '//'),
+            array('/', '///'),
+            array('/Foo', '///Foo'),
             array('c:/', 'c:\\'),
             array('../src', 'Foo/Bar/../../../src'),
             array('c:../b', 'c:.\\..\\a\\..\\b'),