function Process::escape
Escapes a string to be used as a shell argument.
From https://github.com/johnstevenson/winbox-args MIT Licensed (c) John Stevenson <john-stevenson@blueyonder.co.uk>
Parameters
string $arg The argument to be escaped:
bool $meta Additionally escape cmd.exe meta characters:
bool $module The argument is the module to invoke:
1 call to Process::escape()
- Process::escapeShellCommand in vendor/
composer/ xdebug-handler/ src/ Process.php - Escapes an array of arguments that make up a shell command
File
-
vendor/
composer/ xdebug-handler/ src/ Process.php, line 35
Class
- Process
- Process utility functions
Namespace
Composer\XdebugHandlerCode
public static function escape(string $arg, bool $meta = true, bool $module = false) : string {
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
return "'" . str_replace("'", "'\\''", $arg) . "'";
}
$quote = strpbrk($arg, " \t") !== false || $arg === '';
$arg = Preg::replace('/(\\\\*)"/', '$1$1\\"', $arg, -1, $dquotes);
$dquotes = (bool) $dquotes;
if ($meta) {
$meta = $dquotes || Preg::isMatch('/%[^%]+%/', $arg);
if (!$meta) {
$quote = $quote || strpbrk($arg, '^&|<>()') !== false;
}
elseif ($module && !$dquotes && $quote) {
$meta = false;
}
}
if ($quote) {
$arg = '"' . Preg::replace('/(\\\\*)$/', '$1$1', $arg) . '"';
}
if ($meta) {
$arg = Preg::replace('/(["^&|<>()%])/', '^$1', $arg);
}
return $arg;
}