Fix only/exclude to avoid matching names as sub-strings of full package names, fixes #10001
parent
29a52ff463
commit
24f5e54fbe
|
@ -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());
|
||||
|
|
|
@ -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'))),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue