diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 201f44a7e..dd0163717 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -66,11 +66,12 @@ class Filesystem throw new \InvalidArgumentException('from and to must be absolute paths'); } + $from = lcfirst(rtrim(strtr($from, '\\', '/'), '/')); + $to = lcfirst(rtrim(strtr($to, '\\', '/'), '/')); + if (dirname($from) === dirname($to)) { return './'.basename($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) { @@ -101,11 +102,12 @@ class Filesystem throw new \InvalidArgumentException('from and to must be absolute paths'); } + $from = lcfirst(strtr($from, '\\', '/')); + $to = lcfirst(strtr($to, '\\', '/')); + if ($from === $to) { return $directories ? '__DIR__' : '__FILE__'; } - $from = lcfirst(strtr($from, '\\', '/')); - $to = lcfirst(strtr($to, '\\', '/')); $commonPath = $to; while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) { diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php b/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php index 3c6d910cc..2eb74cf44 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php @@ -3,9 +3,9 @@ // autoload_namespace.php generated by Composer $vendorDir = dirname(__DIR__); -$baseDir = dirname($vendorDir); +$baseDir = $vendorDir; return array( - 'Main' => $vendorDir . '/src/', - 'Lala' => $vendorDir . '/src/', + 'Main' => $baseDir . '/src/', + 'Lala' => $baseDir . '/src/', ); diff --git a/tests/Composer/Test/Util/FilesystemTest.php b/tests/Composer/Test/Util/FilesystemTest.php index 0db5549d2..81ece7d35 100644 --- a/tests/Composer/Test/Util/FilesystemTest.php +++ b/tests/Composer/Test/Util/FilesystemTest.php @@ -41,6 +41,8 @@ class FilesystemTest extends TestCase array('/foo/bar', '/foo/baz', true, "dirname(__DIR__).'/baz'"), array('/foo/bin/run', '/foo/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"), array('/foo/bin/run', '/bar/bin/run', true, "'/bar/bin/run'"), + array('/bin/run', '/bin/run', true, "__DIR__"), + array('c:/bin/run', 'c:\\bin/run', true, "__DIR__"), array('c:/bin/run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"), array('c:\\bin\\run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"), array('c:/bin/run', 'd:/vendor/acme/bin/run', true, "'d:/vendor/acme/bin/run'"),