[Process] Add tests on ProcessUtils::escapeArgument

This commit is contained in:
Romain Neutron 2014-03-14 10:10:07 +01:00
parent 85fb495a30
commit de681cbf5c
2 changed files with 4 additions and 2 deletions

View File

@ -57,7 +57,7 @@ class ProcessUtils
$part .= '\\';
}
$part = escapeshellarg($part);
if ($part[0] === '"' && $part[strlen($part) - 1] === '"') {
if ('"' === $part[0] && '"' === $part[strlen($part) - 1]) {
$part = substr($part, 1, -1);
$quote = true;
}
@ -65,7 +65,7 @@ class ProcessUtils
}
}
if ($quote) {
$escapedArgument = '"' . $escapedArgument . '"';
$escapedArgument = '"'.$escapedArgument.'"';
}
return $escapedArgument;

View File

@ -27,6 +27,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
return array(
array('"\"php\" \"-v\""', '"php" "-v"'),
array('"foo bar"', 'foo bar'),
array('^%"path"^%', '%path%'),
array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'),
@ -36,6 +37,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
}
return array(
array("'\"php\" \"-v\"'", '"php" "-v"'),
array("'foo bar'", 'foo bar'),
array("'%path%'", '%path%'),
array("'<|>\" \"'\\''f'", '<|>" "\'f'),