Fix empty process argument escaping on Windows

This commit is contained in:
Helmer Aaviksoo 2013-08-08 01:27:53 +03:00 committed by Fabien Potencier
parent b463a70d73
commit 98f6969e9c
2 changed files with 8 additions and 2 deletions

View File

@ -41,11 +41,15 @@ class ProcessUtils
//@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);

View File

@ -30,6 +30,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
array('"foo bar"', 'foo bar'),
array('^%"path"^%', '%path%'),
array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'),
array('""', ''),
);
}
@ -37,6 +38,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
array("'foo bar'", 'foo bar'),
array("'%path%'", '%path%'),
array("'<|>\" \"'\\''f'", '<|>" "\'f'),
array("''", ''),
);
}
}