Преглед на файлове

Merge pull request #4444 from dennisbirkholz/fix-4439

Fix #4439
Jordi Boggiano преди 9 години
родител
ревизия
15face5432
променени са 2 файла, в които са добавени 31 реда и са изтрити 6 реда
  1. 6 6
      src/Composer/Repository/PathRepository.php
  2. 25 0
      tests/Composer/Test/Repository/PathRepositoryTest.php

+ 6 - 6
src/Composer/Repository/PathRepository.php

@@ -101,10 +101,10 @@ class PathRepository extends ArrayRepository
     {
         parent::initialize();
 
-        foreach ($this->getPaths() as $path) {
-            $path = realpath($path) . '/';
-
+        foreach ($this->getUrlMatches() as $url) {
+            $path = realpath($url) . '/';
             $composerFilePath = $path.'composer.json';
+            
             if (!file_exists($composerFilePath)) {
                 continue;
             }
@@ -113,7 +113,7 @@ class PathRepository extends ArrayRepository
             $package = JsonFile::parseJson($json, $composerFilePath);
             $package['dist'] = array(
                 'type' => 'path',
-                'url' => $path,
+                'url' => $url,
                 'reference' => '',
             );
 
@@ -134,11 +134,11 @@ class PathRepository extends ArrayRepository
     }
 
     /**
-     * Get a list of all path names matching given url (supports globbing).
+     * Get a list of all (possibly relative) path names matching given url (supports globbing).
      *
      * @return string[]
      */
-    private function getPaths()
+    private function getUrlMatches()
     {
         return glob($this->url, GLOB_MARK|GLOB_ONLYDIR);
     }

+ 25 - 0
tests/Composer/Test/Repository/PathRepositoryTest.php

@@ -81,4 +81,29 @@ class PathRepositoryTest extends TestCase
         $package = $packages[1];
         $this->assertEquals('test/path-unversioned', $package->getName());
     }
+
+    /**
+     * Verify relative repository URLs remain relative, see #4439
+     */
+    public function testUrlRemainsRelative()
+    {
+        $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
+            ->getMock();
+
+        $config = new \Composer\Config();
+        $loader = new ArrayLoader(new VersionParser());
+        $versionGuesser = null;
+
+        $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version'));
+        $relativeUrl = ltrim(substr($repositoryUrl, strlen(getcwd())), DIRECTORY_SEPARATOR);
+
+        $repository = new PathRepository(array('url' => $relativeUrl), $ioInterface, $config, $loader);
+        $packages = $repository->getPackages();
+
+        $this->assertEquals(1, $repository->count());
+
+        $package = $packages[0];
+        $this->assertEquals('test/path-versioned', $package->getName());
+        $this->assertEquals(rtrim($relativeUrl, DIRECTORY_SEPARATOR), rtrim($package->getDistUrl(), DIRECTORY_SEPARATOR));
+    }
 }