[Process] Fix: Arguments including space and quote are not correctly escaped (win)
Bad `"bin" "command" \""bin"\"" "\""another command"\"` Better `"bin" "command" "\"bin" \"another command\""`
This commit is contained in:
parent
9213a821d5
commit
85fb495a30
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user