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

Console\Input\StringInput doesn't handle escaped single quotes correctly #32182

Copy link
Copy link
Closed
@bohwaz

Description

@bohwaz
Issue body actions

Symfony version(s) affected: 2.8-4.3

Description

Symfony\Component\Console\Input\StringInput doesn't work with arguments escaped by escapeshellarg.

escapeshellarg on a string with single quotes will produce a closing single quote, an escaped single quote and an opening single quote:

$arg = 'Jenny\'s';
print($arg . PHP_EOL);
// Jenny's
print(escapeshellarg($arg) . PHP_EOL);
// Jenny'\''s

This is correct as per bash documentation: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Single-Quotes

A single quote may not occur between single quotes, even when preceded by a backslash.

But this breaks StringInput as it breaks up the string in multiple tokens.

How to reproduce

$arg = escapeshellarg('Jenny\'s');
$cmd = 'command --arg=' . $arg;

var_dump($cmd);
var_dump(StringInput::tokenize($cmd));

Output:

string(26) "command --arg='Jenny'\''s'"
string(26) "command --arg='Jenny'\''s'"
array(4) {
  [0]=>
  string(7) "command"
  [1]=>
  string(11) "--arg=Jenny"
  [2]=>
  string(1) "\"
  [3]=>
  string(1) "s"
}

Possible Solution

StringInput should handle escaped characters outside of single quotes part of the string.

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.