diff --git a/src/Composer/Repository/FilterRepository.php b/src/Composer/Repository/FilterRepository.php index 61b31e91a..8778233fd 100644 --- a/src/Composer/Repository/FilterRepository.php +++ b/src/Composer/Repository/FilterRepository.php @@ -33,17 +33,17 @@ class FilterRepository implements RepositoryInterface if (!is_array($options['only'])) { throw new \InvalidArgumentException('"only" key for repository '.$repo->getRepoName().' should be an array'); } - $this->only = '{^'.implode('|', array_map(function ($val) { + $this->only = '{^(?:'.implode('|', array_map(function ($val) { return BasePackage::packageNameToRegexp($val, '%s'); - }, $options['only'])) .'$}iD'; + }, $options['only'])) .')$}iD'; } if (isset($options['exclude'])) { if (!is_array($options['exclude'])) { throw new \InvalidArgumentException('"exclude" key for repository '.$repo->getRepoName().' should be an array'); } - $this->exclude = '{^'.implode('|', array_map(function ($val) { + $this->exclude = '{^(?:'.implode('|', array_map(function ($val) { return BasePackage::packageNameToRegexp($val, '%s'); - }, $options['exclude'])) .'$}iD'; + }, $options['exclude'])) .')$}iD'; } if ($this->exclude && $this->only) { throw new \InvalidArgumentException('Only one of "only" and "exclude" can be specified for repository '.$repo->getRepoName()); diff --git a/tests/Composer/Test/Repository/FilterRepositoryTest.php b/tests/Composer/Test/Repository/FilterRepositoryTest.php index 645d5cb09..e3f388da0 100644 --- a/tests/Composer/Test/Repository/FilterRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilterRepositoryTest.php @@ -50,6 +50,9 @@ class FilterRepositoryTest extends TestCase array(array('foo/aaa', 'foo/bbb'), array('only' => array('foo/*'))), array(array('foo/aaa', 'baz/yyy'), array('only' => array('foo/aaa', 'baz/yyy'))), array(array('bar/xxx'), array('exclude' => array('foo/*', 'baz/yyy'))), + // make sure sub-patterns are not matched without wildcard + array(array('foo/aaa', 'foo/bbb', 'bar/xxx', 'baz/yyy'), array('exclude' => array('foo/aa', 'az/yyy'))), + array(array(), array('only' => array('foo/aa', 'az/yyy'))), ); }