1
0
Fork 0

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

pull/12062/head
Jordi Boggiano 2024-07-25 17:24:49 +02:00 committed by GitHub
parent eeff1c79ba
commit 39981a0e2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View File

@ -67,7 +67,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
GitUtil::cleanEnv(); 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); $gitVersion = GitUtil::getVersion($this->process);
// --dissociate option is only available since git 2.3.0-rc0 // --dissociate option is only available since git 2.3.0-rc0
@ -92,7 +92,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $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(); $ref = $package->getSourceReference();
$flag = Platform::isWindows() ? '/D ' : ''; $flag = Platform::isWindows() ? '/D ' : '';
@ -161,7 +161,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'); 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(); $ref = $target->getSourceReference();
if (!empty($this->cachedPackages[$target->getId()][$ref])) { 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'); 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(); GitUtil::cleanEnv();

View File

@ -19,6 +19,7 @@ use Composer\Util\Hg as HgUtils;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Util\Url;
/** /**
* @author Per Bernhardt <plb@webfactory.de> * @author Per Bernhardt <plb@webfactory.de>
@ -47,7 +48,7 @@ class HgDriver extends VcsDriver
} }
$cacheDir = $this->config->get('cache-vcs-dir'); $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 = new Filesystem();
$fs->ensureDirectoryExists($cacheDir); $fs->ensureDirectoryExists($cacheDir);