1
0
Fork 0

Merge pull request #4444 from dennisbirkholz/fix-4439

Fix #4439
pull/4454/head
Jordi Boggiano 2015-09-23 18:46:25 +01:00
commit 15face5432
2 changed files with 31 additions and 6 deletions

View File

@ -101,10 +101,10 @@ class PathRepository extends ArrayRepository
{ {
parent::initialize(); parent::initialize();
foreach ($this->getPaths() as $path) { foreach ($this->getUrlMatches() as $url) {
$path = realpath($path) . '/'; $path = realpath($url) . '/';
$composerFilePath = $path.'composer.json'; $composerFilePath = $path.'composer.json';
if (!file_exists($composerFilePath)) { if (!file_exists($composerFilePath)) {
continue; continue;
} }
@ -113,7 +113,7 @@ class PathRepository extends ArrayRepository
$package = JsonFile::parseJson($json, $composerFilePath); $package = JsonFile::parseJson($json, $composerFilePath);
$package['dist'] = array( $package['dist'] = array(
'type' => 'path', 'type' => 'path',
'url' => $path, 'url' => $url,
'reference' => '', '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[] * @return string[]
*/ */
private function getPaths() private function getUrlMatches()
{ {
return glob($this->url, GLOB_MARK|GLOB_ONLYDIR); return glob($this->url, GLOB_MARK|GLOB_ONLYDIR);
} }

View File

@ -81,4 +81,29 @@ class PathRepositoryTest extends TestCase
$package = $packages[1]; $package = $packages[1];
$this->assertEquals('test/path-unversioned', $package->getName()); $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));
}
} }