Skip to content

[Console] Fix backslash escaping in bash completion #43665

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
merged 1 commit into from
Oct 30, 2021

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Oct 22, 2021

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets #43664
License MIT
Doc PR -

Fully tested code with #43598

  • printf options %b and %q are handy to escape string using in shell input.
  • Backslashes must to be escaped (doubled) in normal input (bin/console debug:form App\\Form\\CommentType). Otherwise they are dropped when PHP receive the argument (App\Form\CommentType become AppFormCommentType in $SERVER['argv']). This is not necessary for quoted arguments (bin/console debug:form "App\Form\CommentType" is OK). In the context of a command stored in a variable, like in the bash script, escaping is not interpreted: we must replace \\ by \ using printf '%b'.
  • Completion does not process escaping. If App\\Form\\ is typed, the suggestions must contain a \\ to match. Since these values are provided to shell, double backslash must be escaped: \ becomes \\\\ in suggestion output.
  • I choose to detect when quotes are typed to allow them in completion and add quotes to suggestions.
  • Suggestion with spaces are still not properly working.
screen-autocomplete-backslash.mov

@wouterj

This comment has been minimized.

@wouterj
Copy link
Member

wouterj commented Oct 23, 2021

sorry, I've hidden my comment. The PR changed a lot from what I looked at yesterday night. I'll have to look again before sharing my opinion

@GromNaN
Copy link
Member Author

GromNaN commented Oct 24, 2021

I'm rewriting this solution to use more native bash and less PHP. Mainly to remove dependency of the input in BashOutput.

@GromNaN
Copy link
Member Author

GromNaN commented Oct 25, 2021

@wouterj I'm done with something more bash-native. The only limitation is with some values that are not unescaped: the token two\ words is not converted to two words in completion input.

It would be awesome if we find a way to add tests to the bash script (unit or functional).

@GromNaN GromNaN force-pushed the console/5.4-complete-backslash branch 3 times, most recently from 4befcb8 to b914980 Compare October 25, 2021 15:10
@stof
Copy link
Member

stof commented Oct 25, 2021

It would be awesome if we find a way to add tests to the bash script (unit or functional).

I agree with that, but I have no idea how.

@wouterj
Copy link
Member

wouterj commented Oct 28, 2021

Hi!

I just tested it and I think this is perfect now you support both ways! I have 2 suggestions after quickly testing this:

  1. What do you think about favoring quoted values with special chars (especially \ or )? For example:
    $ bin/console debug:form
    
    # would become:
    $ bin/console debug:form 'Symfony\Component\Form\Extension\Core\Type\
    
    # instead of:
    $ bin/console debug:form Symfony\\Component\\Form\\Extension\\Core\\Type\\
    
  2. There is an error when the value only contains a quote:
    $ bin/console debug:form '
    [critical] Error thrown while running command "_complete -sbash -c2 -S5.4.0-DEV -ibin/console -idebug:form -i". Message: "The "--input" option requires a value."
                                 The "--input" option requires a value.                                              _complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]
    
    

@fabpot
Copy link
Member

fabpot commented Oct 29, 2021

@GromNaN Do you have time to have a look at Wouter's comments? I'd love to be able to merge this one to unlock some other PRs. Thank you.

@wouterj
Copy link
Member

wouterj commented Oct 29, 2021

Imho, we can also merge this one and fix both of them between beta1 and rc1. The feature is complete - it's just some minor polishing.

@GromNaN
Copy link
Member Author

GromNaN commented Oct 29, 2021

I'm going to make the requested changes tonight.

@GromNaN
Copy link
Member Author

GromNaN commented Oct 29, 2021

What do you think about favoring quoted values with special chars

By default, completion of a FQCN will contain only a single quote, since namespaces are different. Not a big deal.

@GromNaN GromNaN force-pushed the console/5.4-complete-backslash branch from b914980 to 56a74ed Compare October 29, 2021 20:22
@GromNaN GromNaN force-pushed the console/5.4-complete-backslash branch from 5d29751 to 7220038 Compare October 29, 2021 20:39
@fabpot fabpot force-pushed the console/5.4-complete-backslash branch from 7220038 to e9e0c07 Compare October 30, 2021 08:33
@fabpot
Copy link
Member

fabpot commented Oct 30, 2021

Thank you @GromNaN.

@fabpot fabpot merged commit a3c6cca into symfony:5.4 Oct 30, 2021
fabpot added a commit that referenced this pull request Oct 31, 2021
This PR was merged into the 5.4 branch.

Discussion
----------

[Console] [AppVeyor] Fix EOL in the tests

| Q             | A
| ------------- | ---
| Branch?       | 5.4  <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| License       | MIT

[Probably caused by this fix](#43665)

AppVeyor run tests on Windows and tests with EOL [failing](https://ci.appveyor.com/project/fabpot/symfony/builds/41346183#L1559)

![image](https://user-images.githubusercontent.com/57155526/139556426-38a1b371-8c23-4211-a0cd-c31dc26034a7.png)

`@derrabus` pls review

Commits
-------

d4a9e6e [Console][AppVeyor] Fix EOL in the tests
@GromNaN GromNaN deleted the console/5.4-complete-backslash branch November 2, 2021 10:13
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.

5 participants