Skip to content

[Process] Fix backwards compatibility for invalid commands #58189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ public function start(?callable $callback = null, array $env = []): void

try {
$process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);

// Ensure array vs string commands behave the same
if (!$process && \is_array($commandline)) {
$process = @proc_open('exec '.$this->buildShellCommandline($commandline), $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
}
} finally {
if ($this->ignoredSignals && \function_exists('pcntl_sigprocmask')) {
// we restore the signal mask here to avoid any side effects
Expand Down
9 changes: 2 additions & 7 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ public function testInvalidCwd()
*/
public function testInvalidCommand(Process $process)
{
try {
$this->assertSame('\\' === \DIRECTORY_SEPARATOR ? 1 : 127, $process->run());
} catch (ProcessStartFailedException $e) {
// An invalid command might already fail during start since PHP 8.3 for platforms
// supporting posix_spawn(), see https://github.com/php/php-src/issues/12589
$this->assertStringContainsString('No such file or directory', $e->getMessage());
}
// An invalid command should not fail during start
$this->assertSame('\\' === \DIRECTORY_SEPARATOR ? 1 : 127, $process->run());
}

public function invalidProcessProvider()
Expand Down