1
0
Fork 0

Sanitize VCS URLs when building cache keys, fixes #11917, closes #11918 (#12043)

2.2
Jordi Boggiano 2024-07-25 17:24:49 +02:00
parent 23254093aa
commit f18f7f4b47
No known key found for this signature in database
3 changed files with 6 additions and 5 deletions

View File

@ -62,7 +62,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
{
GitUtil::cleanEnv();
$cachePath = $this->config->get('cache-vcs-dir').'/'.Preg::replace('{[^a-z0-9.]}i', '-', $url).'/';
$cachePath = $this->config->get('cache-vcs-dir').'/'.Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($url)).'/';
$gitVersion = GitUtil::getVersion($this->process);
// --dissociate option is only available since git 2.3.0-rc0
@ -87,7 +87,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
{
GitUtil::cleanEnv();
$path = $this->normalizePath($path);
$cachePath = $this->config->get('cache-vcs-dir').'/'.Preg::replace('{[^a-z0-9.]}i', '-', $url).'/';
$cachePath = $this->config->get('cache-vcs-dir').'/'.Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($url)).'/';
$ref = $package->getSourceReference();
$flag = Platform::isWindows() ? '/D ' : '';
@ -156,7 +156,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
throw new \RuntimeException('The .git directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
}
$cachePath = $this->config->get('cache-vcs-dir').'/'.Preg::replace('{[^a-z0-9.]}i', '-', $url).'/';
$cachePath = $this->config->get('cache-vcs-dir').'/'.Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($url)).'/';
$ref = $target->getSourceReference();
if (!empty($this->cachedPackages[$target->getId()][$ref])) {

View File

@ -52,7 +52,7 @@ class GitDriver extends VcsDriver
throw new \RuntimeException('GitDriver requires a usable cache directory, and it looks like you set it to be disabled');
}
$this->repoDir = $this->config->get('cache-vcs-dir') . '/' . Preg::replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
$this->repoDir = $this->config->get('cache-vcs-dir') . '/' . Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($this->url)) . '/';
GitUtil::cleanEnv();

View File

@ -19,6 +19,7 @@ use Composer\Util\Hg as HgUtils;
use Composer\Util\ProcessExecutor;
use Composer\Util\Filesystem;
use Composer\IO\IOInterface;
use Composer\Util\Url;
/**
* @author Per Bernhardt <plb@webfactory.de>
@ -47,7 +48,7 @@ class HgDriver extends VcsDriver
}
$cacheDir = $this->config->get('cache-vcs-dir');
$this->repoDir = $cacheDir . '/' . Preg::replace('{[^a-z0-9]}i', '-', $this->url) . '/';
$this->repoDir = $cacheDir . '/' . Preg::replace('{[^a-z0-9]}i', '-', Url::sanitize($this->url)) . '/';
$fs = new Filesystem();
$fs->ensureDirectoryExists($cacheDir);