Skip to content

Commit

Permalink
bug #23477 [Process] Fix parsing args on Windows (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.3 branch.

Discussion
----------

[Process] Fix parsing args on Windows

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23455
| License       | MIT
| Doc PR        | -

Commits
-------

8826da1 [Process] Fix parsing args on Windows
  • Loading branch information
nicolas-grekas committed Jul 12, 2017
2 parents 2b3afd2 + 8826da1 commit e659ec1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -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]];
}
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Expand Up @@ -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 = <<<EOTXT
Array
(
[0] => -
[1] => a
[2] =>
[3] => b
)
EOTXT;
$this->assertSame($expected, $p->getOutput());
}

public function provideEscapeArgument()
{
yield array('a"b%c%');
Expand Down

0 comments on commit e659ec1

Please sign in to comment.