Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Process.php

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\Process

Code

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) . '"';
}
RSS feed
Powered by Drupal