From 84fed02df11541a0e7e91192f9daa5a2f18fed22 Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Tue, 26 Jan 2016 00:33:47 +0100 Subject: [PATCH 1/2] Globbing while resolving path repositories now normalizes to slashes for predictable cross-platform behaviour. Fixes #4726 --- src/Composer/Repository/PathRepository.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index b826ca999..4529af0f0 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -113,7 +113,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn parent::initialize(); foreach ($this->getUrlMatches() as $url) { - $path = realpath($url) . '/'; + $path = realpath($url) . DIRECTORY_SEPARATOR; $composerFilePath = $path.'composer.json'; if (!file_exists($composerFilePath)) { @@ -131,7 +131,8 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn if (!isset($package['version'])) { $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master'; } - if (is_dir($path.'/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) { + $output = ''; + if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) { $package['dist']['reference'] = trim($output); } else { $package['dist']['reference'] = Locker::getContentHash($json); @@ -153,6 +154,9 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn */ private function getUrlMatches() { - return glob($this->url, GLOB_MARK | GLOB_ONLYDIR); + // Ensure environment-specific path separators are normalized to URL separators + return array_map(function($val) { + return str_replace(DIRECTORY_SEPARATOR, '/', $val); + }, glob($this->url, GLOB_MARK | GLOB_ONLYDIR)); } } From aef4820abec037e9d182f64c04327b881eb11e05 Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Tue, 26 Jan 2016 09:08:57 +0100 Subject: [PATCH 2/2] Normalization of URLs caused discrepancy on Windows with unit tests. --- tests/Composer/Test/Repository/PathRepositoryTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index 47b7ac24f..e76be2bfa 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -101,6 +101,9 @@ class PathRepositoryTest extends TestCase $package = $packages[0]; $this->assertEquals('test/path-versioned', $package->getName()); - $this->assertEquals(rtrim($relativeUrl, DIRECTORY_SEPARATOR), rtrim($package->getDistUrl(), DIRECTORY_SEPARATOR)); + + // Convert platform specific separators back to generic URL slashes + $relativeUrl = str_replace(DIRECTORY_SEPARATOR, '/', $relativeUrl); + $this->assertEquals(rtrim($relativeUrl, '/'), rtrim($package->getDistUrl(), '/')); } }