Skip to content

Commit 467bfc5

Browse files
[Process] Fix escaping for MSYS on Windows
1 parent 5d1662f commit 467bfc5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ private function escapeArgument(?string $argument): string
16451645
if (str_contains($argument, "\0")) {
16461646
$argument = str_replace("\0", '?', $argument);
16471647
}
1648-
if (!preg_match('/[()%!^"<>&|\s]/', $argument)) {
1648+
if (!preg_match('/[()%!^"<>&|\s[\]=;*?\'$]/', $argument)) {
16491649
return $argument;
16501650
}
16511651
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);

Tests/ProcessTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,26 @@ public static function provideEscapeArgument()
14671467
yield [1.1];
14681468
}
14691469

1470+
public function testMsysEscapingOnWindows()
1471+
{
1472+
if ('\\' !== \DIRECTORY_SEPARATOR) {
1473+
$this->markTestSkipped('This test is for Windows platform only');
1474+
}
1475+
1476+
file_put_contents('=foo.txt', 'This is a test file.');
1477+
1478+
try {
1479+
$p = $this->getProcess(['type', substr_replace(getcwd(), '=foo.txt', 2)]);
1480+
$p->mustRun();
1481+
1482+
$this->assertSame('This is a test file.', $p->getOutput());
1483+
} finally {
1484+
unlink('=foo.txt');
1485+
}
1486+
1487+
$this->assertSame(\sprintf('type "%s=foo.txt"', substr(getcwd(), 0, 2)), $p->getCommandLine());
1488+
}
1489+
14701490
public function testPreparedCommand()
14711491
{
14721492
$p = Process::fromShellCommandline('echo "${:abc}"DEF');

0 commit comments

Comments
 (0)