1
0
Fork 0

Merge pull request #2294 from hason/path

Fixed path analysis
pull/2297/merge
Jordi Boggiano 2013-09-26 06:51:49 -07:00
commit 46e55541e7
4 changed files with 44 additions and 9 deletions

View File

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

View File

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

View File

@ -869,6 +869,37 @@ EOF;
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php')); $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') private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
{ {
$a = __DIR__.'/Fixtures/autoload_'.$name.'.php'; $a = __DIR__.'/Fixtures/autoload_'.$name.'.php';

View File

@ -60,6 +60,8 @@ class FilesystemTest extends TestCase
array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'d:/test'"), array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'d:/test'"),
array('/foo/bar', '/foo/bar_vendor', true, "dirname(__DIR__).'/bar_vendor'"), 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', 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('/tmp', '/tmp/../../test', '/test', true),
array('/foo/bar', '/foo/bar_vendor', '../bar_vendor', true), array('/foo/bar', '/foo/bar_vendor', '../bar_vendor', true),
array('/foo/bar_vendor', '/foo/bar', '../bar', 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),
); );
} }