Skip to content

Commit 8826da1

Browse files
[Process] Fix parsing args on Windows
1 parent 22b67a4 commit 8826da1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,14 +1633,17 @@ private function prepareWindowsCommandLine($cmd, array &$envBackup, array &$env
16331633
$varCount = 0;
16341634
$varCache = array();
16351635
$cmd = preg_replace_callback(
1636-
'/"(
1636+
'/"(?:(
16371637
[^"%!^]*+
16381638
(?:
16391639
(?: !LF! | "(?:\^[%!^])?+" )
16401640
[^"%!^]*+
16411641
)++
1642-
)"/x',
1642+
) | [^"]*+ )"/x',
16431643
function ($m) use (&$envBackup, &$env, &$varCache, &$varCount, $uid) {
1644+
if (!isset($m[1])) {
1645+
return $m[0];
1646+
}
16441647
if (isset($varCache[$m[0]])) {
16451648
return $varCache[$m[0]];
16461649
}

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,24 @@ public function testEscapeArgumentWhenInheritEnvDisabled($arg)
14841484
$this->assertSame($arg, $p->getOutput());
14851485
}
14861486

1487+
public function testRawCommandLine()
1488+
{
1489+
$p = new Process(sprintf('"%s" -r %s "a" "" "b"', self::$phpBin, escapeshellarg('print_r($argv);')));
1490+
$p->run();
1491+
1492+
$expected = <<<EOTXT
1493+
Array
1494+
(
1495+
[0] => -
1496+
[1] => a
1497+
[2] =>
1498+
[3] => b
1499+
)
1500+
1501+
EOTXT;
1502+
$this->assertSame($expected, $p->getOutput());
1503+
}
1504+
14871505
public function provideEscapeArgument()
14881506
{
14891507
yield array('a"b%c%');

0 commit comments

Comments
 (0)