From 1ff2a02517e2fb54b11e4ce1cc42e3a49b8342c6 Mon Sep 17 00:00:00 2001 From: Wim Vandersmissen Date: Fri, 19 Jun 2015 15:07:16 +0200 Subject: [PATCH] fix to download correct Bitbucket archive reference when using --prefer-dist --- src/Composer/Downloader/ArchiveDownloader.php | 9 ++--- .../Test/Downloader/ArchiveDownloaderTest.php | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index 35dfe308a..ff0b9e338 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -115,10 +115,11 @@ abstract class ArchiveDownloader extends FileDownloader // update api archives to the proper reference $url = 'https://api.github.com/repos/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } - } - - if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) { - throw new \RuntimeException('You must enable the openssl extension to download files via https'); + } else if ($package->getDistReference() && strpos($url, 'bitbucket.org')) { + if (preg_match('{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i', $url, $match)) { + // update Bitbucket archives to the proper reference + $url = 'https://bitbucket.org/' . $match[1] . '/'. $match[2] . '/get/' . $package->getDistReference() . '.' . $match[4]; + } } return parent::processUrl($package, $url); diff --git a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php index aecc45604..625cc73c4 100644 --- a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php @@ -115,4 +115,38 @@ class ArchiveDownloaderTest extends \PHPUnit_Framework_TestCase array('https://github.com/composer/composer/archive/master.tar.gz'), ); } + + /** + * @dataProvider provideBitbucketUrls + */ + public function testProcessUrlRewriteBitbucketDist($url, $extension) + { + if (!extension_loaded('openssl')) { + $this->markTestSkipped('Requires openssl'); + } + + $downloader = $this->getMockForAbstractClass('Composer\Downloader\ArchiveDownloader', array($this->getMock('Composer\IO\IOInterface'), $this->getMock('Composer\Config'))); + $method = new \ReflectionMethod($downloader, 'processUrl'); + $method->setAccessible(true); + + $url = $url . '.' . $extension; + $expected = 'https://bitbucket.org/davereid/drush-virtualhost/get/ref.' . $extension; + + $package = $this->getMock('Composer\Package\PackageInterface'); + $package->expects($this->any()) + ->method('getDistReference') + ->will($this->returnValue('ref')); + $url = $method->invoke($downloader, $package, $url); + + $this->assertEquals($expected, $url); + } + + public function provideBitbucketUrls() + { + return array( + array('https://bitbucket.org/davereid/drush-virtualhost/get/77ca490c26ac818e024d1138aa8bd3677d1ef21f', 'zip'), + array('https://bitbucket.org/davereid/drush-virtualhost/get/master', 'tar.gz'), + array('https://bitbucket.org/davereid/drush-virtualhost/get/v1.0', 'tar.bz2'), + ); + } }