Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] StringInput removes backslashes from a normal string #31046

Closed
seriquynh opened this issue Apr 10, 2019 · 1 comment
Closed

[Console] StringInput removes backslashes from a normal string #31046

seriquynh opened this issue Apr 10, 2019 · 1 comment

Comments

@seriquynh
Copy link
Contributor

Symfony version(s) affected: 2.8+

Description
StringInput removes backslashes from a normal string.

For example:

  1. I pass the php string "search SomeNamesapce\SomeClass" to the StringInput constructor.
  2. In StringInput::tokenize() method, "SomeNamesapce\SomeClass" matches StringInput::REGEX_STRING, so it is passed into stripcslashes function.
  3. Finally, I got "SomeNamespaceSomeClass".

} elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {

How to reproduce
Create an index.php file with the code below.

<?php

use Symfony\Component\Console\Input\StringInput;

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

$input = new StringInput('search SomeNamesapce\SomeClass');
echo $input->__toString(), PHP_EOL;
// Expected: "search SomeNamespace\SomeClass"
// Actual: "search SomeNamespaceSomeClass"

$input = new StringInput('search SomeNamesapce\\SomeClass');
echo $input->__toString(), PHP_EOL;
// Expected: "search SomeNamespace\SomeClass"
// Actual: "search SomeNamespaceSomeClass"

$input = new StringInput('search SomeNamesapce\\\SomeClass');
echo $input->__toString(), PHP_EOL;
// Expected: "search SomeNamespace\\SomeClass"
// Actual: "search SomeNamespace\SomeClass"

$input = new StringInput('search SomeNamesapce\\\\SomeClass');
echo $input->__toString(), PHP_EOL; // "search SomeNamespace\SomeClass"
// Expected: "search SomeNamespace\\SomeClass"
// Actual: "search SomeNamespace\SomeClass"

$input = new StringInput('search SomeNamesapce\\\\\SomeClass');
echo $input->__toString(), PHP_EOL;
// Expected: "search SomeNamespace\\\SomeClass"
// Actual: "search SomeNamespace\SomeClass"

Possible Solution
I am not sure that it is a bug because I couldn't find any relevant issues.
Is it an expected behavior?

Additional context
This is the result when running "php index.php"

$ php index.php
search SomeNamesapceSomeClass
search SomeNamesapceSomeClass
search 'SomeNamesapce\SomeClass'
search 'SomeNamesapce\SomeClass'
search 'SomeNamesapce\SomeClass'
@seriquynh
Copy link
Contributor Author

There is seem no issue with this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants