Fixed path analysis

main
Martin Hasoň 11 years ago
parent 05ffc605f1
commit 3c0a620ad5

@ -328,7 +328,7 @@ EOF;
$path = $filesystem->normalizePath($path);
$baseDir = '';
if (strpos($path, $vendorPath) === 0) {
if (strpos($path.'/', $vendorPath.'/') === 0) {
$path = substr($path, strlen($vendorPath));
$baseDir = '$vendorDir';

@ -222,12 +222,12 @@ class Filesystem
return './'.basename($to);
}
$commonPath = $to.'/';
while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {
$commonPath = strtr(dirname($commonPath), '\\', '/');
$commonPath = $to;
while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath)) {
$commonPath = dirname($commonPath);
}
if (0 !== strpos($from, $commonPath) || '/' === $commonPath || '.' === $commonPath) {
if (0 !== strpos($from, $commonPath) || '/' === $commonPath) {
return $to;
}
@ -260,12 +260,12 @@ class Filesystem
return $directories ? '__DIR__' : '__FILE__';
}
$commonPath = $to.'/';
while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {
$commonPath = strtr(dirname($commonPath), '\\', '/');
$commonPath = $to;
while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath)) {
$commonPath = dirname($commonPath);
}
if (0 !== strpos($from, $commonPath) || '/' === $commonPath || '.' === $commonPath) {
if (0 !== strpos($from, $commonPath) || '/' === $commonPath) {
return var_export($to, true);
}

@ -869,6 +869,37 @@ EOF;
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
}
public function testVendorSubstringPath()
{
$package = new Package('a', '1.0', '1.0');
$package->setAutoload(array(
'psr-0' => array('Foo' => 'composer-test-autoload-src/src'),
));
$this->repository->expects($this->once())
->method('getCanonicalPackages')
->will($this->returnValue(array()));
$this->fs->ensureDirectoryExists($this->vendorDir.'/a');
$expectedNamespace = <<<'EOF'
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Foo' => array($baseDir . '/composer-test-autoload-src/src'),
);
EOF;
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'VendorSubstring');
$this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
}
private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
{
$a = __DIR__.'/Fixtures/autoload_'.$name.'.php';

@ -60,6 +60,8 @@ class FilesystemTest extends TestCase
array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'d:/test'"),
array('/foo/bar', '/foo/bar_vendor', true, "dirname(__DIR__).'/bar_vendor'"),
array('/foo/bar_vendor', '/foo/bar', true, "dirname(__DIR__).'/bar'"),
array('/foo/bar_vendor', '/foo/bar/src', true, "dirname(__DIR__).'/bar/src'"),
array('/foo/bar_vendor/src2', '/foo/bar/src/lib', true, "dirname(dirname(__DIR__)).'/bar/src/lib'"),
);
}
@ -107,6 +109,8 @@ class FilesystemTest extends TestCase
array('/tmp', '/tmp/../../test', '/test', true),
array('/foo/bar', '/foo/bar_vendor', '../bar_vendor', true),
array('/foo/bar_vendor', '/foo/bar', '../bar', true),
array('/foo/bar_vendor', '/foo/bar/src', '../bar/src', true),
array('/foo/bar_vendor/src2', '/foo/bar/src/lib', '../../bar/src/lib', true),
);
}

Loading…
Cancel
Save