-
Notifications
You must be signed in to change notification settings - Fork 383
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
feat(_comp_expand_glob): Add a utility to safely perform pathname expansions (Fix #705) #708
feat(_comp_expand_glob): Add a utility to safely perform pathname expansions (Fix #705) #708
Conversation
2ad707c
to
5d9d354
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I wish we didn't have to do something like this :/ But I guess we do want it.
3f86a09
to
925f29a
Compare
I have added fixes 5d9d354...3f86a09 and rebased & squashed changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barring a few small comments, and resolving conflicts, looks good to me; feel free to merge after addressing (or as always, feel free to bounce back for more opinions if you want).
I'm not sure if the hooks stuff discussed elsewhere will eventually lead into a generic ability to make the environment/options/settings what we want and reset them back at start and end of all our completions (e.g. _init_completion
and trap
trickery). If they do, this could become obsolete, but that stuff might take some time and might never actually realize, so I think this is fair enough at least in the meantime.
bash_completion
Outdated
|
||
local IFS=$' \t\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may have been added originally for $reset
to work and thus might not be needed any longer -- at least this PR is removing it with another similar change in _xinetd_services
above and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. I think I kept it so that it doesn't affect the later word splitting COMPREPLY+=($(...))
.IFS
removal in _xinetd_services
is an oversight. 8b267eb. I have also added IFS=$'\n'
to protect _service
for the splitting of compgen
results.
completions/ipmitool
Outdated
printf '%s\n' "${files[@]}" | | ||
command sed -ne 's/^[^0-9]*\([0-9]\{1,\}\)/\1/p' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have the candidates in a bash array, I suppose we could loop over and filter them in pure bash instead of doing this. Not a biggie, leaving up to you to decide what to do about it or to leave as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored in 24e095b. We can actually implement it using compgen -X
without a loop.
@@ -245,6 +245,53 @@ _upvars() | |||
done | |||
} | |||
|
|||
# Get the list of filenames that match with the specified glob pattern. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a little reminder here why we should be using this this would be a nice touch.
# Get the list of filenames that match with the specified glob pattern. | |
# Get the list of filenames that match with the specified glob pattern. | |
# This function does the globbing in a controlled environment, avoiding | |
# interference from user's shell options/settings or environment variables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I have applied it 62e2440.
62e2440
to
76cee0f
Compare
Co-authored-by: Ville Skyttä <[email protected]>
When there are no "charset" files, nothing has been generated although we intended to at least generate "utf8". The check for the number of generated candidates should be performed after generating "utf8". The wrong check has been introduced in commit 08dd2cd. Originally, we have been performing the pathname expansions without adjusting "nullglob", so the pattern "/usr/share/mysql/charsets/*.xml" has been directly strayed into the array "charsets" unless "nullgob" is set. Then the check has been always passed when "nullglob" is not set, which is the reason that we have been missing the problem until now.
* Instead of replacing "Index.xml" with an empty string after the pathname expansions, we now exclude "Index.xml" from the pathname pattern. * In case that there is an empty filename as "/usr/share/mysql/charsets/.xml", we explicitly exclude empty charset names by specifying the option, -X '', for compgen.
76cee0f
to
ec907d9
Compare
Yeah, I have also thought about it. Something we need to care about is whether the scope of these shell settings for the pathname expansions can be safely expanded to the entire completion. For example, if there are any completion functions that generate the completions depending on the user's current shell settings, expanding the scope of the adjusted shell settings can affect the results. But I'm not sure if there are any existing ones. |
Merging |
Fixes #705 and similar problems
Description
Pathname expansions are used in many places in the codebase, but it seems only a small part of these pathname expansions considers the setting of
nullglob
, and onlymysql
considers the setting offailglob
. All the pathname expansions except for that inmysql
can possibly fail due tofailglob
. Actually, there are even other settings that we need to care about for the pathname expansions, such asnounset
,dotglob
,GLOBIGNORE
, andnocaseglob
.We don't want to always write codes to check all these settings in-place, so I suggest introducing a shell function
_comp_expand_glob
to perform the pathname expansions.Commits
This PR contains several changes.
conftest.py (bash_env_saved)
that allows an arbitrary change to the variables and settings within thebash_env
context. This is used in a test of_comp_expand_glob
.conftest.py (bash_env_saved)
that allows saving/restoring the settings ofset -o NAME
and checking the unintended changes to them (just like the existing ones forshopt
and variables). This is also used in a test of_comp_expand_glob
.ble/util/eval-pathname-expansion
andble/complete/util/eval-pathname-expansion
).mysql
completion uncovered by the new_comp_expand_glob
, which has originally happened withshopt -s nullglob
.mysql
for a problem that has existed for a long time.Discussion
There are several things that I want to discuss for the detailed design.
1.
dotglob
While performing the pathname expansions, should we turn
dotglob
on or turn it off? Currently, It's turned off as that is the default of Bash. But maybe it is better to be turned on in some cases.2.
nocaseglob
Currently,
_comp_expand_glob
doesn't change the settings fornocaseglob
for its internal expansions, but maybe we should also normalize the behavior of the case matching regardless of the current user settings ofnocaseglob
.3. Naming of
_comp_expand_glob
Other possibilities include
_comp{,_util}_{,_}expand_{pathname{,s},glob}
4.
extglob
I think we are requiring that
extglob
is turned on, but maybe we can explicitly adjustextglob
as well as the other options.