From b6981d09e8e37fcbe7e589a4c35474a21f3776a3 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 7 May 2014 18:38:58 +0200 Subject: [PATCH] Fix handling of origin url in composer repository class --- src/Composer/Command/DiagnoseCommand.php | 4 ++-- src/Composer/Downloader/FileDownloader.php | 4 ---- src/Composer/Repository/ComposerRepository.php | 7 +++++-- src/Composer/Util/RemoteFilesystem.php | 4 ++++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index 21523a062..2661837a3 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -207,10 +207,10 @@ EOT $url = 'https://api.github.com/repos/Seldaek/jsonlint/zipball/1.0.0'; try { - $rfcResult = $this->rfs->getContents('api.github.com', $url, false); + $rfcResult = $this->rfs->getContents('github.com', $url, false); } catch (TransportException $e) { try { - $this->rfs->getContents('api.github.com', $url, false, array('http' => array('request_fulluri' => false))); + $this->rfs->getContents('github.com', $url, false, array('http' => array('request_fulluri' => false))); } catch (TransportException $e) { return 'Unable to assert the situation, maybe github is down ('.$e->getMessage().')'; } diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index ddde199b6..709835444 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -121,10 +121,6 @@ class FileDownloader implements DownloaderInterface } $rfs = $preFileDownloadEvent->getRemoteFilesystem(); - if (strpos($hostname, '.github.com') === (strlen($hostname) - 11)) { - $hostname = 'github.com'; - } - try { $checksum = $package->getDistSha1Checksum(); $cacheKey = $this->getCacheKey($package); diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 5f5bf445b..6245cd031 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -160,7 +160,8 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository if ($this->searchUrl && $mode === self::SEARCH_FULLTEXT) { $url = str_replace('%query%', $query, $this->searchUrl); - $json = $this->rfs->getContents($url, $url, false); + $hostname = parse_url($url, PHP_URL_HOST) ?: $url; + $json = $this->rfs->getContents($hostname, $url, false); $results = JsonFile::parseJson($json, $url); return $results['results']; @@ -604,7 +605,9 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository if ($this->eventDispatcher) { $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); } - $json = $preFileDownloadEvent->getRemoteFilesystem()->getContents($filename, $filename, false); + + $hostname = parse_url($filename, PHP_URL_HOST) ?: $filename; + $json = $preFileDownloadEvent->getRemoteFilesystem()->getContents($hostname, $filename, false); if ($sha256 && $sha256 !== hash('sha256', $json)) { if ($retries) { usleep(100000); diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 2f9dacf69..bac6e1df0 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -118,6 +118,10 @@ class RemoteFilesystem */ protected function get($originUrl, $fileUrl, $additionalOptions = array(), $fileName = null, $progress = true) { + if (strpos($originUrl, '.github.com') === (strlen($originUrl) - 11)) { + $originUrl = 'github.com'; + } + $this->bytesMax = 0; $this->originUrl = $originUrl; $this->fileUrl = $fileUrl;