Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various path handling inconsistencies #5962

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Composer/Autoload/AutoloadGenerator.php
Expand Up @@ -106,12 +106,14 @@ public function dump(Config $config, InstalledRepositoryInterface $localRepo, Pa
$vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir'))));
$useGlobalIncludePath = (bool) $config->get('use-include-path');
$prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true';

$targetDir = $vendorPath.'/'.$targetDir;
$filesystem->ensureDirectoryExists($targetDir);
$targetDir = $filesystem->normalizePath(realpath(realpath($targetDir)));

$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$vendorPathCode = $filesystem->findShortestPathCode($targetDir, $vendorPath, true);
$vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, $targetDir, true);

$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
Expand Down Expand Up @@ -148,7 +150,7 @@ public function dump(Config $config, InstalledRepositoryInterface $localRepo, Pa
foreach ($autoloads['psr-0'] as $namespace => $paths) {
$exportedPaths = array();
foreach ($paths as $path) {
$exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
$exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $filesystem->normalizePath($path));
}
$exportedPrefix = var_export($namespace, true);
$namespacesFile .= " $exportedPrefix => ";
Expand All @@ -160,7 +162,7 @@ public function dump(Config $config, InstalledRepositoryInterface $localRepo, Pa
foreach ($autoloads['psr-4'] as $namespace => $paths) {
$exportedPaths = array();
foreach ($paths as $path) {
$exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
$exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $filesystem->normalizePath($path));
}
$exportedPrefix = var_export($namespace, true);
$psr4File .= " $exportedPrefix => ";
Expand Down Expand Up @@ -734,8 +736,8 @@ class ComposerStaticInit$suffix

$filesystem = new Filesystem();

$vendorPathCode = ' => ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '/";
$appBaseDirCode = ' => ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '/";
$vendorPathCode = ' => ' . $filesystem->findShortestPathCode($targetDir, $vendorPath, true, true) . " . '/";
$appBaseDirCode = ' => ' . $filesystem->findShortestPathCode($targetDir, $basePath, true, true) . " . '/";

$absoluteVendorPathCode = ' => ' . substr(var_export(rtrim($vendorDir, '\\/') . '/', true), 0, -1);
$absoluteAppBaseDirCode = ' => ' . substr(var_export(rtrim($baseDir, '\\/') . '/', true), 0, -1);
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Util/Filesystem.php
Expand Up @@ -444,8 +444,8 @@ public function normalizePath($path)
$prefix = '';
$absolute = false;

// extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive:
if (preg_match('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) {
// extract a prefix being a protocol://host, protocol:, protocol://drive: or simply drive:
if (preg_match('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: | //(?=[a-z0-9]) )}ix', $path, $match)) {
$prefix = $match[1];
$path = substr($path, strlen($prefix));
}
Expand Down
1 change: 1 addition & 0 deletions tests/Composer/Test/Util/FilesystemTest.php
Expand Up @@ -216,6 +216,7 @@ public function provideNormalizedPaths()
array('/', '//'),
array('/', '///'),
array('/Foo', '///Foo'),
array('//windows/UNC/Name', '\\\\windows\\UNC\\Name'),
array('c:/', 'c:\\'),
array('../src', 'Foo/Bar/../../../src'),
array('c:../b', 'c:.\\..\\a\\..\\b'),
Expand Down