Fix pattern matching for remove wildcard, refs #7715
parent
dc6027a0ad
commit
66d84f60c6
|
@ -22,6 +22,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Composer\Package\BasePackage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pierre du Plessis <pdples@gmail.com>
|
* @author Pierre du Plessis <pdples@gmail.com>
|
||||||
|
@ -100,11 +101,11 @@ EOT
|
||||||
$json->removeLink($altType, $composer[$altType][$package]);
|
$json->removeLink($altType, $composer[$altType][$package]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (isset($composer[$type]) && $matches = preg_grep('#^'.$package.'#', array_keys($composer[$type]))) {
|
} elseif (isset($composer[$type]) && $matches = preg_grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$type]))) {
|
||||||
foreach ($matches as $matchedPackage) {
|
foreach ($matches as $matchedPackage) {
|
||||||
$json->removeLink($type, $matchedPackage);
|
$json->removeLink($type, $matchedPackage);
|
||||||
}
|
}
|
||||||
} elseif (isset($composer[$altType]) && $matches = preg_grep('#^'.$package.'#', array_keys($composer[$altType]))) {
|
} elseif (isset($composer[$altType]) && $matches = preg_grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$altType]))) {
|
||||||
foreach ($matches as $matchedPackage) {
|
foreach ($matches as $matchedPackage) {
|
||||||
$io->writeError('<warning>' . $matchedPackage . ' could not be found in ' . $type . ' but it is present in ' . $altType . '</warning>');
|
$io->writeError('<warning>' . $matchedPackage . ' could not be found in ' . $type . ' but it is present in ' . $altType . '</warning>');
|
||||||
if ($io->isInteractive()) {
|
if ($io->isInteractive()) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ use Composer\Installer\NoopInstaller;
|
||||||
use Composer\Installer\SuggestedPackagesReporter;
|
use Composer\Installer\SuggestedPackagesReporter;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Package\AliasPackage;
|
use Composer\Package\AliasPackage;
|
||||||
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Package\CompletePackage;
|
use Composer\Package\CompletePackage;
|
||||||
use Composer\Package\Link;
|
use Composer\Package\Link;
|
||||||
use Composer\Package\Loader\ArrayLoader;
|
use Composer\Package\Loader\ArrayLoader;
|
||||||
|
@ -1254,7 +1255,7 @@ class Installer
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->updateWhitelist as $whiteListedPattern => $void) {
|
foreach ($this->updateWhitelist as $whiteListedPattern => $void) {
|
||||||
$patternRegexp = $this->packageNameToRegexp($whiteListedPattern);
|
$patternRegexp = BasePackage::packageNameToRegexp($whiteListedPattern);
|
||||||
if (preg_match($patternRegexp, $package->getName())) {
|
if (preg_match($patternRegexp, $package->getName())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1263,19 +1264,6 @@ class Installer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a regexp from a package name, expanding * globs as required
|
|
||||||
*
|
|
||||||
* @param string $whiteListedPattern
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function packageNameToRegexp($whiteListedPattern)
|
|
||||||
{
|
|
||||||
$cleanedWhiteListedPattern = str_replace('\\*', '.*', preg_quote($whiteListedPattern));
|
|
||||||
|
|
||||||
return "{^" . $cleanedWhiteListedPattern . "$}i";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $links
|
* @param array $links
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -1341,7 +1329,7 @@ class Installer
|
||||||
|
|
||||||
// check if the name is a glob pattern that did not match directly
|
// check if the name is a glob pattern that did not match directly
|
||||||
if (!$nameMatchesRequiredPackage) {
|
if (!$nameMatchesRequiredPackage) {
|
||||||
$whitelistPatternRegexp = $this->packageNameToRegexp($packageName);
|
$whitelistPatternRegexp = BasePackage::packageNameToRegexp($packageName);
|
||||||
foreach ($rootRequiredPackageNames as $rootRequiredPackageName) {
|
foreach ($rootRequiredPackageNames as $rootRequiredPackageName) {
|
||||||
if (preg_match($whitelistPatternRegexp, $rootRequiredPackageName)) {
|
if (preg_match($whitelistPatternRegexp, $rootRequiredPackageName)) {
|
||||||
$nameMatchesRequiredPackage = true;
|
$nameMatchesRequiredPackage = true;
|
||||||
|
|
|
@ -234,4 +234,17 @@ abstract class BasePackage implements PackageInterface
|
||||||
$this->repository = null;
|
$this->repository = null;
|
||||||
$this->id = -1;
|
$this->id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a regexp from a package name, expanding * globs as required
|
||||||
|
*
|
||||||
|
* @param string $whiteListedPattern
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function packageNameToRegexp($whiteListedPattern)
|
||||||
|
{
|
||||||
|
$cleanedWhiteListedPattern = str_replace('\\*', '.*', preg_quote($whiteListedPattern));
|
||||||
|
|
||||||
|
return "{^" . $cleanedWhiteListedPattern . "$}i";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue