diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php
index b84b461a2..216adfa90 100644
--- a/src/Composer/Downloader/ArchiveDownloader.php
+++ b/src/Composer/Downloader/ArchiveDownloader.php
@@ -85,8 +85,12 @@ abstract class ArchiveDownloader extends FileDownloader
/**
* {@inheritdoc}
*/
- protected function processUrl($url)
+ protected function processUrl(PackageInterface $package, $url)
{
+ if ($package->getDistReference() && preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) {
+ $url = 'https://github.com/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
+ }
+
if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) {
// bypass https for github if openssl is disabled
if (preg_match('{^https?://(github.com/[^/]+/[^/]+/(zip|tar)ball/[^/]+)$}i', $url, $match)) {
@@ -96,7 +100,7 @@ abstract class ArchiveDownloader extends FileDownloader
}
}
- return $url;
+ return parent::processUrl($package, $url);
}
/**
diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php
index 87eac6109..1337d041f 100644
--- a/src/Composer/Downloader/FileDownloader.php
+++ b/src/Composer/Downloader/FileDownloader.php
@@ -67,7 +67,7 @@ class FileDownloader implements DownloaderInterface
$this->io->write(" - Installing " . $package->getName() . " (" . VersionParser::formatVersion($package) . ")");
- $processUrl = $this->processUrl($url);
+ $processUrl = $this->processUrl($package, $url);
try {
$this->rfs->copy($package->getSourceUrl(), $processUrl, $fileName);
@@ -123,12 +123,13 @@ class FileDownloader implements DownloaderInterface
/**
* Process the download url
*
+ * @param PackageInterface $package package the url is coming from
* @param string $url download url
* @return string url
*
* @throws \RuntimeException If any problem with the url
*/
- protected function processUrl($url)
+ protected function processUrl(PackageInterface $package, $url)
{
if (!extension_loaded('openssl') && 0 === strpos($url, 'https:')) {
throw new \RuntimeException('You must enable the openssl extension to download files via https');
diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php
index 3b6e91d81..28bb05cf9 100644
--- a/src/Composer/Installer.php
+++ b/src/Composer/Installer.php
@@ -481,6 +481,7 @@ class Installer
$references = $this->package->getReferences();
if (isset($references[$package->getName()])) {
$package->setSourceReference($references[$package->getName()]);
+ $package->setDistReference($references[$package->getName()]);
}
}
}
diff --git a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php
index cf5fde68e..72ba9b10a 100644
--- a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php
+++ b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php
@@ -38,7 +38,7 @@ class ArchiveDownloaderTest extends \PHPUnit_Framework_TestCase
$method->setAccessible(true);
$expected = 'https://github.com/composer/composer/zipball/master';
- $url = $method->invoke($downloader, $expected);
+ $url = $method->invoke($downloader, $this->getMock('Composer\Package\PackageInterface'), $expected);
if (extension_loaded('openssl')) {
$this->assertEquals($expected, $url);