diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index fb12d393abad..05f88d2d1b11 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1633,14 +1633,17 @@ private function prepareWindowsCommandLine($cmd, array &$envBackup, array &$env $varCount = 0; $varCache = array(); $cmd = preg_replace_callback( - '/"( + '/"(?:( [^"%!^]*+ (?: (?: !LF! | "(?:\^[%!^])?+" ) [^"%!^]*+ )++ - )"/x', + ) | [^"]*+ )"/x', function ($m) use (&$envBackup, &$env, &$varCache, &$varCount, $uid) { + if (!isset($m[1])) { + return $m[0]; + } if (isset($varCache[$m[0]])) { return $varCache[$m[0]]; } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index e4d084f44efd..267257117d43 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1484,6 +1484,24 @@ public function testEscapeArgumentWhenInheritEnvDisabled($arg) $this->assertSame($arg, $p->getOutput()); } + public function testRawCommandLine() + { + $p = new Process(sprintf('"%s" -r %s "a" "" "b"', self::$phpBin, escapeshellarg('print_r($argv);'))); + $p->run(); + + $expected = << - + [1] => a + [2] => + [3] => b +) + +EOTXT; + $this->assertSame($expected, $p->getOutput()); + } + public function provideEscapeArgument() { yield array('a"b%c%');