Skip to content

Process converts an empty string argument to " sometimes #23455

@borekb

Description

@borekb

Symfony\Process 3.3.4 seems to convert an empty string argument to a quote (") under some circumstances:

  • The empty string argument is in the middle of some other arguments.
  • It is on Windows and "enhanced Windows mode" is enabled (which is the default).

exec works correctly. Here is a repro:

<?php

require __DIR__ . '/vendor/autoload.php';

function runUsingSymf($command) {
    $process = new \Symfony\Component\Process\Process($command);
    $process->run();
    echo $process->getOutput();
}

function runUsingExec($command) {
    exec($command, $output);
    echo join($output, "\n");
}

// print-args.php does `var_export($argv)`

runUsingExec('php print-args.php ""');  // $argv[1] == ''
runUsingSymf('php print-args.php ""');  // $argv[1] == ''

runUsingExec('php print-args.php "" "2"');  // $argv[1] == ''
runUsingSymf('php print-args.php "" "2"');  // $argv[1] == ''

runUsingExec('php print-args.php "1" ""');  // $argv[2] == ''
runUsingSymf('php print-args.php "1" ""');  // $argv[2] == ''

runUsingExec('php print-args.php "1" "" "3"');  // $argv[2] == ''
runUsingSymf('php print-args.php "1" "" "3"');  // $argv[2] == '"' <-- !!

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