Skip to content

Commit

Permalink
[Process] Fix escaping /X arguments on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 4, 2024
1 parent 72baf6b commit d94dda5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 1638,7 @@ private function escapeArgument(?string $argument): string
if (str_contains($argument, "\0")) {
$argument = str_replace("\0", '?', $argument);
}
if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {
if (!preg_match('/[()%!^"<>&|\s]/', $argument)) {
return $argument;
}
$argument = preg_replace('/(\\\\ )$/', '$1$1', $argument);
Expand Down
7 changes: 6 additions & 1 deletion Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 1424,12 @@ public function testGetCommandLine()
{
$p = new Process(['/usr/bin/php']);

$expected = '\\' === \DIRECTORY_SEPARATOR ? '"/usr/bin/php"' : "'/usr/bin/php'";
$expected = '\\' === \DIRECTORY_SEPARATOR ? '/usr/bin/php' : "'/usr/bin/php'";
$this->assertSame($expected, $p->getCommandLine());

$p = new Process(['cd', '/d']);

$expected = '\\' === \DIRECTORY_SEPARATOR ? 'cd /d' : "'cd' '/d'";
$this->assertSame($expected, $p->getCommandLine());
}

Expand Down

0 comments on commit d94dda5

Please sign in to comment.