Skip to content

QuestionHelper autocomplete with trailing backslashes triggers display error #24652

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

Closed
ciaranmcnulty opened this issue Oct 21, 2017 · 2 comments

Comments

@ciaranmcnulty
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.3.10

Providing trailing backslashes in an autocomplete value seems to break the console formatting, when using QuestionHelper. I assume this is a result of faulty escaping around the highlighting:

$questionHelper = $this->getApplication()->getHelperSet()->get('question');
$question = new Question('Enter namespace:');
$question->setAutocompleterValues(['Foo\\', 'Bar\\']);
$namespace = $questionHelper->ask($input, $output, $question);

screen shot 2017-10-21 at 08 40 41

@ciaranmcnulty ciaranmcnulty changed the title QuestionHelper Autocomplete with trailing backslashes triggers display error QuestionHelper autocomplete with trailing backslashes triggers display error Oct 21, 2017
@ciaranmcnulty
Copy link
Contributor Author

ciaranmcnulty commented Oct 21, 2017

Additional info from some playing with the prompt.

Initial prompt looks good:
Enter namespace:

Typing a match causes the broken display, note trailing \ is not part of the suggestion:
Enter namespace:F[cursor here]oo</hl>

Hitting tab to complete:
Enter namespace:Foo\[cursor here]</hl>

kamazee pushed a commit to kamazee/symfony that referenced this issue Oct 22, 2017
Fixes symfony#24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion
kamazee pushed a commit to kamazee/symfony that referenced this issue Oct 22, 2017
Fixes symfony#24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion
kamazee added a commit to kamazee/symfony that referenced this issue Oct 22, 2017
Fixes symfony#24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion
kamazee added a commit to kamazee/symfony that referenced this issue Oct 22, 2017
Fixes symfony#24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion
kamazee added a commit to kamazee/symfony that referenced this issue Oct 22, 2017
Fixes symfony#24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion
nicolas-grekas added a commit that referenced this issue Oct 24, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

Escape trailing \ in QuestionHelper autocompletion

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24652
| License       | MIT

Fixes #24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion

Output of the added test without the fix:
```
./phpunit --filter testAutocompleteWithTrailingBackslash src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
#!/usr/bin/env php
PHPUnit 6.0.13 by Sebastian Bergmann and contributors.

Testing Symfony\Component\Console\Tests\Helper\QuestionHelperTest
F                                                                   1 / 1 (100%)

Time: 4.28 seconds, Memory: 6.00MB

There was 1 failure:

1) Symfony\Component\Console\Tests\Helper\QuestionHelperTest::testAutocompleteWithTrailingBackslash
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'ExampleNamespace\'
+'ExampleNamespace</hl>'
```

`OutputFormatter::escapeTrailingBackslash` is marked as `@internal`; however, this seems to be a valid use without exposing outside of the component. `OutputFormatter::escape`, which is not internal, doesn't fit here because escaping tags in autocompletion options is a deeper topic: there might be a valid use for tags in autocompletion and even if not, taking out the possibility to use them might be considered a BC break (even though it hasn't been advertised anywhere).

Commits
-------

0c0f1da Escape trailing \ in QuestionHelper autocompletion
symfony-splitter pushed a commit to symfony/console that referenced this issue Oct 24, 2017
Fixes symfony/symfony#24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion
@chalasr
Copy link
Member

chalasr commented Oct 24, 2017

Fixed in #24660

@chalasr chalasr closed this as completed Oct 24, 2017
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

4 participants