Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Escape completion suggestions with special chars#43664

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@wouterj
Copy link
Member

QA
Branch?5.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

This fixes shell completion whenever a special char (backslash and whitespace at the moment) are present. In these cases, all suggestions are put in quotes (to avoid double-double escaping) and the special chars are escaped.

This bug was found in#43598

$includesUnsafeChars =false;
$suggestions =array_map(function ($value)use (&$includesUnsafeChars) {
$newValue =str_replace('\\','\\\\',$value);
$newValue =str_replace('','\',$value);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this do the replacement in$newValue ? Otherwise, the previous line is useless code.

chalasr reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

btw, you could do it as a singlestr_replace using arrays as arguments

COMPREPLY=($(compgen -W"$sfcomplete" --"$cur"))
# $sfcomplete is escaped already, escape the input as well
local escapedcur=${cur//\\/\\\\}
COMPREPLY=($(compgen -W"${sfcomplete}" --"${escapedcur//\'/\\\'}"))
Copy link
Member

@GromNaNGromNaNOct 22, 2021
edited
Loading

Choose a reason for hiding this comment

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

I was working on this issue and found thatprintf "%q" "$cur" escapes for using as shell input.

%q causes printf to output the corresponding argument in a format that can be reused as shell input.

My version:#43665

@wouterj
Copy link
MemberAuthor

Closing in favor of#43665

@wouterjwouterj deleted the bugfix/shell-completion-backslash branchOctober 28, 2021 09:57
fabpot added a commit that referenced this pull requestOct 30, 2021
This PR was squashed before being merged into the 5.4 branch.Discussion----------[Console] Fix backslash escaping in bash completion| 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.https://user-images.githubusercontent.com/400034/138536102-e282ee75-56c8-414b-8b16-7c3c290276d7.movCommits-------e9e0c07 [Console] Fix backslash escaping in bash completion
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@GromNaNGromNaNGromNaN left review comments

@stofstofstof left review comments

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

4 participants

@wouterj@GromNaN@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp