bug #10448 [2.3][Process] Fix quoted arguments escaping (romainneutron)
This PR was merged into the 2.3 branch. Discussion ---------- [2.3][Process] Fix quoted arguments escaping | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT This PR replaces #8972 Commits -------de681cb
[Process] Add tests on ProcessUtils::escapeArgument85fb495
[Process] Fix: Arguments including space and quote are not correctly escaped (win)
This commit is contained in:
commit
fe91a2ca62
@ -46,6 +46,7 @@ class ProcessUtils
|
||||
}
|
||||
|
||||
$escapedArgument = '';
|
||||
$quote = false;
|
||||
foreach (preg_split('/([%"])/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
|
||||
if ('"' === $part) {
|
||||
$escapedArgument .= '\\"';
|
||||
@ -55,9 +56,17 @@ class ProcessUtils
|
||||
if ('\\' === substr($part, -1)) {
|
||||
$part .= '\\';
|
||||
}
|
||||
$escapedArgument .= escapeshellarg($part);
|
||||
$part = escapeshellarg($part);
|
||||
if ('"' === $part[0] && '"' === $part[strlen($part) - 1]) {
|
||||
$part = substr($part, 1, -1);
|
||||
$quote = true;
|
||||
}
|
||||
$escapedArgument .= $part;
|
||||
}
|
||||
}
|
||||
if ($quote) {
|
||||
$escapedArgument = '"'.$escapedArgument.'"';
|
||||
}
|
||||
|
||||
return $escapedArgument;
|
||||
}
|
||||
|
@ -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'),
|
||||
|
Reference in New Issue
Block a user