Skip to content

Escape trailing \ in QuestionHelper autocompletion #24660

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

Merged

Conversation

kamazee
Copy link
Contributor

@kamazee kamazee commented Oct 22, 2017

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).

@kamazee
Copy link
Contributor Author

kamazee commented Oct 22, 2017

Oops, adding "BC Break" label must be a mistake (that's either me leaving BC Break row with "yes/no" when submitting PR or just mentioning BC break in PR description text). I'd appreciate it being removed.

@kamazee
Copy link
Contributor Author

kamazee commented Oct 22, 2017

Looks like CI consoles enable formatting. I'll do more cleanup for irrelevant sequences and update PR.

@kamazee kamazee force-pushed the fix_question_helper_autocompletion branch from e5015fa to 1e66c9e Compare October 22, 2017 11:06
Fixes symfony#24652
Trailing backslash, being unescaped, used to escape closing formatting
tag and, thus, formatting tag appeared in autocompletion
@kamazee kamazee force-pushed the fix_question_helper_autocompletion branch from 1e66c9e to 0c0f1da Compare October 22, 2017 11:16
@kamazee
Copy link
Contributor Author

kamazee commented Oct 22, 2017

Ready for review.

@chalasr chalasr added this to the 2.7 milestone Oct 23, 2017
@@ -303,7 +304,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
// Save cursor position
$output->write("\0337");
// Write highlighted text
$output->write('<hl>'.substr($matches[$ofs], $i).'</hl>');
$output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $i)).'</hl>');
Copy link
Contributor

@ro0NL ro0NL Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant we use escape() here? (it includes escapeTrailingBackslash also) Not sure about leaking out this detail =/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the PR description, I think this is a BC break as escape would effectively turn off interpreting tags in autocompletion options (they'll be always shown as is); while the impact should not be terrible, this doesn't seem to be the right thing to do for anything but master where it could be acceptable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right!

they'll be always shown as is

Which is in fact the actual value.. no? But 👍 for keeping as is; thus escapeTrailingBackslash only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ro0NL , yeah.
I'd be glad to create another one for master with just escape as it indeed seems to be the right thing in general (interpretation of tags is not guaranteed there anyway, only <hl> accidentally works).

Copy link
Contributor

@ro0NL ro0NL Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless we qualify that a bugfix for 2.7 ;-) impact should be minimal. More or less relates to escaping exceptions #22142

also h1 leaks in as a valid style after calling... perhaps inline it using background/foreground options.

Copy link
Member

@chalasr chalasr Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep it as is until someone asks for it, escaping trailing backslashes only

@nicolas-grekas
Copy link
Member

Thank you @kamazee.

@nicolas-grekas nicolas-grekas merged commit 0c0f1da into symfony:2.7 Oct 24, 2017
nicolas-grekas added a commit that referenced this pull request 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
This was referenced Oct 30, 2017
This was referenced Nov 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants