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 26, 2022
1 parent 61be158 commit 92e47ee
Show file tree
Hide file tree
Showing 2 changed files with 22 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
20 changes: 20 additions & 0 deletions tests/Composer/Test/Package/Loader/ArrayLoaderTest.php
Expand Up @@ -12,6 +12,7 @@

namespace Composer\Test\Package\Loader;

use Composer\Package\AliasPackage;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper;
use Composer\Package\Link;
Expand Down Expand Up @@ -347,4 +348,23 @@ 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-1',
'extra' => [
'branch-alias' => [
'1' => '1.3-dev',
],
],
'dist' => [
'type' => 'zip',
'url' => 'https://example.org/',
],
);

$this->assertNull($this->loader->getBranchAlias($config));
}
}

0 comments on commit 92e47ee

Please sign in to comment.