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

fix(complete): Prevent filenames splitting in bash completion #5336

Merged

Conversation

sudotac
Copy link
Contributor

@sudotac sudotac commented Feb 2, 2024

Fix #5313 (and continuation of #5240)

The root cause is field splitting by bash.
It is erroneously performed when processing compgen output.
The delimiters used for field splitting are defined in IFS environment variable, which is $' \t\n' (space, tab, newline) by default. If the output of compgen contains these characters, they are split out.

This patch (partially) fixes that by restricting IFS to newline.
Now we can handle filenames with spaces and/or tabs, but not newlines because we cannot distinguish "newline as a delimiter" from "newline contained in filename".

Handling newlines would be more difficult than handling spaces. It seems that other completion scripts cannot handle this.
I think this should be a separate issue if we really try to fix this.

@epage
Copy link
Member

epage commented Feb 2, 2024

Thanks!

@epage epage merged commit 0582e04 into clap-rs:master Feb 2, 2024
22 checks passed
@sudotac sudotac deleted the prevent-filenames-splitting-in-bash-completion branch February 2, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clap_complete bash: filenames with spaces are not completed properly
2 participants