Fix numeric default-branches with v prefix (e.g. v2.x-dev) being treated as non-numeric and receiving an alias like e.g. dev-main
parent
7397a78035
commit
e51d755a08
|
@ -455,7 +455,7 @@ class ArrayLoader implements LoaderInterface
|
||||||
if (
|
if (
|
||||||
isset($config['default-branch'])
|
isset($config['default-branch'])
|
||||||
&& $config['default-branch'] === true
|
&& $config['default-branch'] === true
|
||||||
&& false === $this->versionParser->parseNumericAliasPrefix($config['version'])
|
&& false === $this->versionParser->parseNumericAliasPrefix(Preg::replace('{^v}', '', $config['version']))
|
||||||
) {
|
) {
|
||||||
return VersionParser::DEFAULT_BRANCH_ALIAS;
|
return VersionParser::DEFAULT_BRANCH_ALIAS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Composer\Test\Package\Loader;
|
||||||
use Composer\Package\Loader\ArrayLoader;
|
use Composer\Package\Loader\ArrayLoader;
|
||||||
use Composer\Package\Dumper\ArrayDumper;
|
use Composer\Package\Dumper\ArrayDumper;
|
||||||
use Composer\Package\Link;
|
use Composer\Package\Link;
|
||||||
|
use Composer\Package\Version\VersionParser;
|
||||||
use Composer\Test\TestCase;
|
use Composer\Test\TestCase;
|
||||||
|
|
||||||
class ArrayLoaderTest extends TestCase
|
class ArrayLoaderTest extends TestCase
|
||||||
|
@ -249,6 +250,57 @@ class ArrayLoaderTest extends TestCase
|
||||||
$this->assertEquals('4.x-dev', $package->getPrettyVersion());
|
$this->assertEquals('4.x-dev', $package->getPrettyVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPackageAliasingWithoutBranchAlias(): void
|
||||||
|
{
|
||||||
|
// non-numeric gets a default alias
|
||||||
|
$config = [
|
||||||
|
'name' => 'A',
|
||||||
|
'version' => 'dev-main',
|
||||||
|
'default-branch' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$package = $this->loader->load($config);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Composer\Package\AliasPackage', $package);
|
||||||
|
$this->assertEquals(VersionParser::DEFAULT_BRANCH_ALIAS, $package->getPrettyVersion());
|
||||||
|
|
||||||
|
// non-default branch gets no alias even if non-numeric
|
||||||
|
$config = [
|
||||||
|
'name' => 'A',
|
||||||
|
'version' => 'dev-main',
|
||||||
|
'default-branch' => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
$package = $this->loader->load($config);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Composer\Package\CompletePackage', $package);
|
||||||
|
$this->assertEquals('dev-main', $package->getPrettyVersion());
|
||||||
|
|
||||||
|
// default branch gets no alias if already numeric
|
||||||
|
$config = [
|
||||||
|
'name' => 'A',
|
||||||
|
'version' => '2.x-dev',
|
||||||
|
'default-branch' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$package = $this->loader->load($config);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Composer\Package\CompletePackage', $package);
|
||||||
|
$this->assertEquals('2.9999999.9999999.9999999-dev', $package->getVersion());
|
||||||
|
|
||||||
|
// default branch gets no alias if already numeric, with v prefix
|
||||||
|
$config = [
|
||||||
|
'name' => 'A',
|
||||||
|
'version' => 'v2.x-dev',
|
||||||
|
'default-branch' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$package = $this->loader->load($config);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Composer\Package\CompletePackage', $package);
|
||||||
|
$this->assertEquals('2.9999999.9999999.9999999-dev', $package->getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
public function testAbandoned(): void
|
public function testAbandoned(): void
|
||||||
{
|
{
|
||||||
$config = [
|
$config = [
|
||||||
|
|
Loading…
Reference in New Issue