1
0
Fork 0

fix to download correct Bitbucket archive reference when using --prefer-dist

pull/4167/head
Wim Vandersmissen 2015-06-19 15:07:16 +02:00
parent b2173d28fc
commit 1ff2a02517
2 changed files with 39 additions and 4 deletions

View File

@ -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);

View File

@ -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'),
);
}
}