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] Do not leak hidden console commands #33412

Merged
merged 1 commit into from
Sep 28, 2019
Merged

Conversation

m-vo
Copy link
Contributor

@m-vo m-vo commented Sep 1, 2019

Q A
Branch? 4.4 (updated)
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #33398
License MIT

This PR attempts to fix hidden console commands to be leaked when interacting with the console.

These are the changes:

  • Hidden commands won't be shown anymore in the list of commands in a namespace as well as the list of suggestions ("Did you mean...") for invalid or ambiguous commands.
  • Hidden commands therefore now need to be always entered with their full name.
  • If an abbreviated command is entered that was previously ambiguous with (only) hidden commands, it's now executed directly (not ambiguous anymore).

Side note: When implementing the tests & changes I realized that Application->get() isn't side effect free (when redirecting to the help command) and behaves differently when called multiple times. It therefore must not be used from inside find(). Maybe we should change this? Here are the relevant bits:

if ($this->wantHelps) {
$this->wantHelps = false;
$helpCommand = $this->get('help');
$helpCommand->setCommand($command);
return $helpCommand;
}

@nicolas-grekas
Copy link
Member

Shouldn't we do this on 4.4, to not break scripts that use a short alias into the wild?

@m-vo
Copy link
Contributor Author

m-vo commented Sep 2, 2019

Agreed, that's probably a good idea as this issue is rather a cosmetic one.
(I think commands in scripts should never be abbreviated though but who knows... 😄 )

Do you want me to rebase on 4.4?*

*) btw: Should I add return type hints for new functions in this case even though the other functions inside Console/Application don't?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 2, 2019

Please rebase for 4.4 yes, and you can add types for sure.

@chalasr
Copy link
Member

chalasr commented Sep 2, 2019

Hidden commands won't be shown anymore in the list of commands in a namespace as well as the list of suggestions ("Did you mean...") for invalid or ambiguous commands.

This part should be for 3.4.

@m-vo
Copy link
Contributor Author

m-vo commented Sep 2, 2019

@chalasr How would that work without the other changes? Assume you're input is ambiguous and you get a suggestion with two commands where one of them is hidden. Now stripping the hidden one would return a single command saying that it is ambiguous. Isn't that worse that leaving it as it is?

@m-vo
Copy link
Contributor Author

m-vo commented Sep 2, 2019

rebased for 4.4

fabbot reporting about CS seems unrelated to my changes (it's about unsorted use statements).

@nicolas-grekas
Copy link
Member

fabbot patch applied in 61dad16

@m-vo
Copy link
Contributor Author

m-vo commented Sep 20, 2019

I accidentally rebased against the wrong branch first and then against 4.4 again. Not sure what went wrong there because github is showing lots of commits now. Of course I know what happened. I am silly. I'm going to fix this (hopefully tomorrow). Shouldn't do things in passing... 🤦‍♂️

@m-vo
Copy link
Contributor Author

m-vo commented Sep 20, 2019

Done.

@nicolas-grekas
Copy link
Member

@chalasr we need your help to unlock here (you can also approve as is :) )

@nicolas-grekas
Copy link
Member

(rebase needed btw, to see tests green)

@chalasr
Copy link
Member

chalasr commented Sep 28, 2019

PR rebased + added 1 commit to turn the CommandNotFoundException into a deprecation notice in case one uses an abbreviation for finding an hidden command.
Bugfix part moved to its own PR for 3.4: #33748

nicolas-grekas added a commit that referenced this pull request Sep 28, 2019
…rnatives (m-vo)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Do not include hidden commands in suggested alternatives

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #33398
| License       | MIT
| Doc PR        | n/a

Partially backports #33412 on 3.4, avoids leaking the names of hidden commands in suggested alternatives on command not found.

Commits
-------

8a9d173 Do not include hidden commands in suggested alternatives
@chalasr chalasr force-pushed the ticket_33398 branch 2 times, most recently from 38e67fd to 92b5a29 Compare September 28, 2019 15:00
@chalasr
Copy link
Member

chalasr commented Sep 28, 2019

Thank you @m-vo.

chalasr added a commit that referenced this pull request Sep 28, 2019
This PR was merged into the 4.4 branch.

Discussion
----------

[Console] Do not leak hidden console commands

| Q             | A
| ------------- | ---
| Branch?       | 4.4 (updated)
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #33398
| License       | MIT

This PR attempts to fix hidden console commands to be leaked when interacting with the console.

These are the changes:
* Hidden commands won't be shown anymore in the list of commands in a namespace as well as the list of  suggestions ("Did you mean...") for invalid or ambiguous commands.
* Hidden commands therefore now need to be always entered with their full name.
* If an abbreviated command is entered that was previously ambiguous with (only) hidden commands, it's now executed directly (not ambiguous anymore).

Side note: When implementing the tests & changes I realized that `Application->get()` isn't side effect free (when redirecting to the help command) and behaves differently when called multiple times. It therefore must not be used from inside `find()`. Maybe we should change this? Here are the relevant bits:
https://github.com/symfony/symfony/blob/f71f74b36a80227d3e68f1b65b1f1d9b42fa9952/src/Symfony/Component/Console/Application.php#L495-L502

Commits
-------

f340633 [Console] Deprecate abbreviating hidden command names using  Application->find()
@chalasr chalasr merged commit f340633 into symfony:4.4 Sep 28, 2019
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
This was referenced Nov 12, 2019
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