Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Process has inconsistent escaping behavior array/string #27540

Copy link
Copy link
Closed
@rtek

Description

@rtek
Issue body actions

Symfony version(s) affected: symfony/process 4.1.0

Description
May not be a bug but the docs imply that the string form for Process command is the equivalent to the array form:

When a string command is passed to new Process() the arguments are not escaped, but when the array form is used they are correctly escaped. This example is on windows so ^ is an escape char.

As a result the string form of the same command is not portable whereas the array form is.

<?php

namespace Test;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

require 'vendor/autoload.php';

class Test extends TestCase
{
    public function testStringsNotEscaped()
    {
        $px = new Process('composer require ^7.1');
        $py = new Process(['composer', 'require', '^7.1']);

        $this->assertSame($px->getCommandLine(), $py->getCommandLine());
    }
}
$ vendor/bin/phpunit Test.php
PHPUnit 7.2.4 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 46 ms, Memory: 2.00MB

There was 1 failure:

1) Test\Test::testStringsNotEscaped
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'composer require ^7.1'
+'composer require ""^^"7.1"'

C:\server\root\oss\process\Test.php:17

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.