Browse Source

Fix handling of origin url in composer repository class

Jordi Boggiano 11 years ago
parent
commit
b6981d09e8

+ 2 - 2
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().')';
             }

+ 0 - 4
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);

+ 5 - 2
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);

+ 4 - 0
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;