1
0
Fork 0

Fix platform package detection in VersionParser

pull/6779/merge
Jérôme Vasseur 2017-09-26 15:06:39 +02:00 committed by Jordi Boggiano
parent 11f1e03739
commit 71c2ecbace
2 changed files with 39 additions and 1 deletions

View File

@ -12,6 +12,7 @@
namespace Composer\Package\Version;
use Composer\Repository\PlatformRepository;
use Composer\Semver\VersionParser as SemverVersionParser;
class VersionParser extends SemverVersionParser
@ -47,7 +48,7 @@ class VersionParser extends SemverVersionParser
for ($i = 0, $count = count($pairs); $i < $count; $i++) {
$pair = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', trim($pairs[$i]));
if (false === strpos($pair, ' ') && isset($pairs[$i + 1]) && false === strpos($pairs[$i + 1], '/')) {
if (false === strpos($pair, ' ') && isset($pairs[$i + 1]) && false === strpos($pairs[$i + 1], '/') && !preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $pairs[$i + 1])) {
$pair .= ' '.$pairs[$i + 1];
$i++;
}

View File

@ -0,0 +1,37 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Package\Version;
use Composer\Package\Version\VersionParser;
class VersionParserTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getParseNameVersionPairsData
*/
public function testParseNameVersionPairs($pairs, $result)
{
$versionParser = new VersionParser();
$this->assertSame($result, $versionParser->parseNameVersionPairs($pairs));
}
public function getParseNameVersionPairsData()
{
return array(
array(array('php:^7.0'), array(array('name' => 'php', 'version' => '^7.0'))),
array(array('php', '^7.0'), array(array('name' => 'php', 'version' => '^7.0'))),
array(array('php', 'ext-apcu'), array(array('name' => 'php'), array('name' => 'ext-apcu'))),
);
}
}