From 6bd43dff859c597c09bd03a7e7d6443822d0a396 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 10 Jun 2024 14:56:13 +0200 Subject: [PATCH] Merge pull request from GHSA-v9qv-c7wm-wgmf --- src/Composer/Package/Version/VersionGuesser.php | 15 ++++++++------- .../Test/Package/Version/VersionGuesserTest.php | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 2b2b19706..72fc799a7 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -173,7 +173,7 @@ class VersionGuesser $featurePrettyVersion = $prettyVersion; // try to find the best (nearest) version branch to assume this feature's version - $result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path); + $result = $this->guessFeatureVersion($packageConfig, $version, $branches, ['git', 'rev-list', '%candidate%..%branch%'], $path); $version = $result['version']; $prettyVersion = $result['pretty_version']; } @@ -248,7 +248,7 @@ class VersionGuesser $branches = array_map('strval', array_keys($driver->getBranches())); // try to find the best (nearest) version branch to assume this feature's version - $result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'hg log -r "not ancestors(\'%candidate%\') and ancestors(\'%branch%\')" --template "{node}\\n"', $path); + $result = $this->guessFeatureVersion($packageConfig, $version, $branches, ['hg', 'log', '-r', 'not ancestors(\'%candidate%\') and ancestors(\'%branch%\')', '--template', '"{node}\\n"'], $path); $result['commit'] = ''; $result['feature_version'] = $version; $result['feature_pretty_version'] = $version; @@ -261,13 +261,12 @@ class VersionGuesser /** * @param array $packageConfig - * @param string[] $branches - * - * @phpstan-param non-empty-string $scmCmdline + * @param list $branches + * @param list $scmCmdline * * @return array{version: string|null, pretty_version: string|null} */ - private function guessFeatureVersion(array $packageConfig, ?string $version, array $branches, string $scmCmdline, string $path): array + private function guessFeatureVersion(array $packageConfig, ?string $version, array $branches, array $scmCmdline, string $path): array { $prettyVersion = $version; @@ -309,7 +308,9 @@ class VersionGuesser continue; } - $cmdLine = str_replace(['%candidate%', '%branch%'], [$candidate, $branch], $scmCmdline); + $cmdLine = array_map(static function (string $component) use ($candidate, $branch) { + return str_replace(['%candidate%', '%branch%'], [$candidate, $branch], $component); + }, $scmCmdline); $promises[] = $this->process->executeAsync($cmdLine, $path)->then(function (Process $process) use (&$length, &$version, &$prettyVersion, $candidateVersion, &$promises): void { if (!$process->isSuccessful()) { return; diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index 676ef2420..c6e01251b 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -117,7 +117,7 @@ class VersionGuesserTest extends TestCase 'stdout' => " arbitrary $commitHash Commit message\n* feature $anotherCommitHash Another message\n", ], [ - 'cmd' => 'git rev-list arbitrary..feature', + 'cmd' => ['git', 'rev-list', 'arbitrary..feature'], 'stdout' => "$anotherCommitHash\n", ], ], true); @@ -147,7 +147,7 @@ class VersionGuesserTest extends TestCase 'stdout' => " latest-testing $commitHash Commit message\n* feature $anotherCommitHash Another message\n", ], [ - 'cmd' => 'git rev-list latest-testing..feature', + 'cmd' => ['git', 'rev-list', 'latest-testing..feature'], 'stdout' => "$anotherCommitHash\n", ], ], true); @@ -352,7 +352,7 @@ class VersionGuesserTest extends TestCase "remotes/origin/1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n", ], [ - 'cmd' => 'git rev-list remotes/origin/1.5..feature-branch', + 'cmd' => ['git', 'rev-list', 'remotes/origin/1.5..feature-branch'], 'stdout' => "\n", ], ], true);