[Process] Add tests on ProcessUtils::escapeArgument
This commit is contained in:
parent
85fb495a30
commit
de681cbf5c
@ -57,7 +57,7 @@ class ProcessUtils
|
|||||||
$part .= '\\';
|
$part .= '\\';
|
||||||
}
|
}
|
||||||
$part = escapeshellarg($part);
|
$part = escapeshellarg($part);
|
||||||
if ($part[0] === '"' && $part[strlen($part) - 1] === '"') {
|
if ('"' === $part[0] && '"' === $part[strlen($part) - 1]) {
|
||||||
$part = substr($part, 1, -1);
|
$part = substr($part, 1, -1);
|
||||||
$quote = true;
|
$quote = true;
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ class ProcessUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($quote) {
|
if ($quote) {
|
||||||
$escapedArgument = '"' . $escapedArgument . '"';
|
$escapedArgument = '"'.$escapedArgument.'"';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $escapedArgument;
|
return $escapedArgument;
|
||||||
|
@ -27,6 +27,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
return array(
|
return array(
|
||||||
|
array('"\"php\" \"-v\""', '"php" "-v"'),
|
||||||
array('"foo bar"', 'foo bar'),
|
array('"foo bar"', 'foo bar'),
|
||||||
array('^%"path"^%', '%path%'),
|
array('^%"path"^%', '%path%'),
|
||||||
array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'),
|
array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'),
|
||||||
@ -36,6 +37,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
array("'\"php\" \"-v\"'", '"php" "-v"'),
|
||||||
array("'foo bar'", 'foo bar'),
|
array("'foo bar'", 'foo bar'),
|
||||||
array("'%path%'", '%path%'),
|
array("'%path%'", '%path%'),
|
||||||
array("'<|>\" \"'\\''f'", '<|>" "\'f'),
|
array("'<|>\" \"'\\''f'", '<|>" "\'f'),
|
||||||
|
Reference in New Issue
Block a user