Skip to content

Commit

Permalink
ArrayLoader: fix integer index of branch alias
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Mar 24, 2022
1 parent 61be158 commit a03f403
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Composer/Package/Loader/ArrayLoader.php
Expand Up @@ -421,6 +421,8 @@ public function getBranchAlias(array $config): ?string

if (isset($config['extra']['branch-alias']) && \is_array($config['extra']['branch-alias'])) {
foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
$sourceBranch = (string) $sourceBranch;

// ensure it is an alias to a -dev package
if ('-dev' !== substr($targetBranch, -4)) {
continue;
Expand Down
21 changes: 21 additions & 0 deletions tests/Composer/Test/Package/Loader/ArrayLoaderTest.php
Expand Up @@ -347,4 +347,25 @@ public function testNoneStringSourceDistReference(): void
$this->assertSame('2019', $package->getSourceReference());
$this->assertSame('2019', $package->getDistReference());
}

public function testBranchAliasIntegerIndex(): void
{
$config = array(
'name' => 'acme/package',
'version' => 'dev-main',
'extra' => [
'branch-alias' => [
'1' => '1.3.-dev',
],
],
'dist' => [
'type' => 'zip',
'url' => 'https://example.org/',
],
);

$package = $this->loader->load($config);
$this->assertSame('2019', $package->getSourceReference());
$this->assertSame('2019', $package->getDistReference());
}
}

0 comments on commit a03f403

Please sign in to comment.