Skip to content

Commit

Permalink
Fix empty process argument escaping on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
helmer authored and fabpot committed Aug 8, 2013
1 parent b463a70 commit 98f6969
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Symfony/Component/Process/ProcessUtils.php
Expand Up @@ -41,11 +41,15 @@ public static function escapeArgument($argument)
//@see https://bugs.php.net/bug.php?id=43784
//@see https://bugs.php.net/bug.php?id=49446
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if ('' === $argument) {
return escapeshellarg($argument);
}

$escapedArgument = '';
foreach (preg_split('/([%"])/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' == $part) {
if ('"' === $part) {
$escapedArgument .= '\\"';
} elseif ('%' == $part) {
} elseif ('%' === $part) {
$escapedArgument .= '^%';
} else {
$escapedArgument .= escapeshellarg($part);
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Process/Tests/ProcessUtilsTest.php
Expand Up @@ -30,13 +30,15 @@ public function dataArguments()
array('"foo bar"', 'foo bar'),
array('^%"path"^%', '%path%'),
array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'),
array('""', ''),
);
}

return array(
array("'foo bar'", 'foo bar'),
array("'%path%'", '%path%'),
array("'<|>\" \"'\\''f'", '<|>" "\'f'),
array("''", ''),
);
}
}

0 comments on commit 98f6969

Please sign in to comment.