From 4046ae042d0367871f94de155dd64cfa4c917994 Mon Sep 17 00:00:00 2001 From: Omer Karadagli Date: Thu, 12 Nov 2015 00:32:02 +0000 Subject: [PATCH] Up-level relative paths in exclude-from-classmap --- src/Composer/Autoload/AutoloadGenerator.php | 19 ++++++++++++++++++- .../Test/Autoload/AutoloadGeneratorTest.php | 4 +++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 3e2da75af..db8bcae58 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -697,8 +697,25 @@ FOOTER; // add support for wildcards * and ** $path = str_replace('\\*\\*', '.+?', $path); $path = str_replace('\\*', '[^/]+?', $path); + // add support for up-level relative paths + $path = preg_replace_callback( + '{^((\\\.{1,2})+)/}', + function ($matches) use (&$updir) { + if (isset($matches[1])) { + // undo preg_quote for the matched string + $updir = str_replace('\\.', '.', $matches[1]); + } - $autoloads[] = empty($installPath) ? preg_quote(strtr(getcwd(), '\\', '/')) . '/' . $path : preg_quote($installPath) . '/' . $path; + return ''; + }, + $path + ); + if (empty($installPath)) { + $installPath = strtr(getcwd(), '\\', '/'); + } + + $resolvedPath = realpath($installPath . '/' . $updir); + $autoloads[] = preg_quote(strtr($resolvedPath, '\\', '/')) . '/' . $path; continue; } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 8afe87c3b..d48170b7e 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -1084,6 +1084,7 @@ EOF; 'psr-4' => array('Acme\Foo\\' => '../path/../src-psr4'), 'classmap' => array('../classmap'), 'files' => array('../test.php'), + 'exclude-from-classmap' => array('./../classmap/excluded'), )); $this->repository->expects($this->once()) @@ -1091,9 +1092,10 @@ EOF; ->will($this->returnValue(array())); $this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo'); - $this->fs->ensureDirectoryExists($this->workingDir.'/classmap'); + $this->fs->ensureDirectoryExists($this->workingDir.'/classmap/excluded'); file_put_contents($this->workingDir.'/src/Foo/Bar.php', 'workingDir.'/classmap/classes.php', 'workingDir.'/classmap/excluded/classes.php', 'workingDir.'/test.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_14');