From 9febf55f7671a769d4bea46dde3cdc9ad1a9b659 Mon Sep 17 00:00:00 2001 From: Dennis Birkholz Date: Wed, 23 Sep 2015 17:51:41 +0200 Subject: [PATCH 1/2] Store url relative again, fix 4439 --- src/Composer/Repository/PathRepository.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index a76a2e052..3b600ea36 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/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); } From 3febbc2cbf2192cde1842ff29921ecf9650bb34a Mon Sep 17 00:00:00 2001 From: Dennis Birkholz Date: Wed, 23 Sep 2015 18:15:43 +0200 Subject: [PATCH 2/2] Test case to verify relative paths remain relative --- .../Test/Repository/PathRepositoryTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index 03ad46fea..1a5392c28 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/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)); + } }