function Process::escapeArgument
Escapes a string to be used as a shell argument.
2 calls to Process::escapeArgument()
- Process::buildShellCommandline in vendor/
symfony/ process/ Process.php - Process::replacePlaceholders in vendor/
symfony/ process/ Process.php
File
-
vendor/
symfony/ process/ Process.php, line 1637
Class
- Process
- Process is a thin wrapper around proc_* functions to easily start independent PHP processes.
Namespace
Symfony\Component\ProcessCode
private function escapeArgument(?string $argument) : string {
if ('' === $argument || null === $argument) {
return '""';
}
if ('\\' !== \DIRECTORY_SEPARATOR) {
return "'" . str_replace("'", "'\\''", $argument) . "'";
}
if (str_contains($argument, "\x00")) {
$argument = str_replace("\x00", '?', $argument);
}
if (!preg_match('/[()%!^"<>&|\\s]/', $argument)) {
return $argument;
}
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);
return '"' . str_replace([
'"',
'^',
'%',
'!',
"\n",
], [
'""',
'"^^"',
'"^%"',
'"^!"',
'!LF!',
], $argument) . '"';
}