8000 \Symfony\Component\Process\Process::escapeArgument as a service class · Issue #41447 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
\Symfony\Component\Process\Process::escapeArgument as a service class #41447
Closed
@tdgroot

Description

@tdgroot

Description
Extract \Symfony\Component\Process\Process::escapeArgument to a separate service class, so that external classes can make use of the shell argument escaping.

Commands like \Symfony\Component\Process\Process::fromShellCommandline accept raw input, but sometimes the client wants to make sure the arguments passed to that method are actually escaped. Or is argument binding the only preferred way to achieve this?

Example

<?php

use Symfony\Component\Process\ArgumentEscaper;
use Symfony\Component\Process\Process;

function test_piped_command(string $param): void
{
    $escaper = new ArgumentEscaper();
    
    $command = [];
    $command[] = 'echo ' . $escaper->escapeArgument($param);
    $command[] = 'md5sum';

    $shellCommand = implode('|', $command);

    $process = Process::fromShellCommandline($command);
    $process->run();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0