Skip to content

Commit

Permalink
Work only with supported URL schemes (closes #138)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyfedotov committed Mar 16, 2017
1 parent 89d6aaf commit be55b1c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Plugin implements
'Share',
);

private static $supportedSchemes = array(
'http',
'https'
);

public function activate(Composer $composer, IO\IOInterface $io)
{
// @codeCoverageIgnoreStart
Expand Down Expand Up @@ -99,6 +104,12 @@ public function onPreFileDownload(CPlugin\PreFileDownloadEvent $ev)
if ($this->disabled) {
return;
}

$scheme = parse_url($ev->getProcessedUrl(), PHP_URL_SCHEME);
if (!in_array($scheme, self::$supportedSchemes, true)) {
return;
}

$rfs = $ev->getRemoteFilesystem();
$curlrfs = new CurlRemoteFilesystem(
$this->io,
Expand All @@ -119,15 +130,17 @@ public function prefetchComposerRepositories()
$repos = $this->package->getRepositories();
foreach ($repos as $label => $repo) {
if (isset($repo['type']) && $repo['type'] === 'composer') {
if (isset($repo['force-lazy-providers']) && $repo['force-lazy-providers']) {
if (!empty($repo['force-lazy-providers'])) {
continue;
}
if ('http?://' === substr($repo['url'], 0, 8) && isset($repo['allow_ssl_downgrade']) && $repo['allow_ssl_downgrade']) {
$repo = array(
'type' => $repo['type'],
'url' => str_replace('https?://', 'https://', $repo['url']),
);

if (substr($repo['url'], 0, 6) !== 'https?') {
$scheme = parse_url($repo['url'], PHP_URL_SCHEME);
if (!in_array($scheme, self::$supportedSchemes, true)) {
continue;
}
}

$r = new ParallelizedComposerRepository($repo, $this->io, $this->config);
$r->prefetch();
}
Expand Down

0 comments on commit be55b1c

Please sign in to comment.