Skip to content

Commit

Permalink
_filedir: Fix overquoted argument to compgen -d (RedHat: #1171396)
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Feb 19, 2015
1 parent d423969 commit d2920b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ _filedir()
local quoted x tmp

_quote_readline_by_ref "$cur" quoted
x=$( compgen -d -- "$quoted" ) &&
x=$( compgen -d -- "$cur" ) &&
while read -r tmp; do
toks+=( "$tmp" )
done <<< "$x"
Expand Down
19 changes: 16 additions & 3 deletions test/unit/_filedir.exp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
proc setup {} {
assert_bash_exec {unset COMPREPLY cur}
assert_bash_exec {unset -f _f}
assert_bash_exec {unset -f _f _fd}
save_env
# Declare bash completion function `_f'
assert_bash_exec { \
Expand All @@ -16,6 +16,11 @@ proc setup {} {
_g() { local cur=$(_get_cword); unset COMPREPLY; _filedir e1; }; \
complete -F _g g \
}
# Declare bash completion function `_fd' to complete on dirs
assert_bash_exec { \
_fd() { local cur=$(_get_cword); unset COMPREPLY; _filedir -d; }; \
complete -F _fd fd \
}
# Create directories `a*b' and `a\b' only when not running on Cygwin/Windows;
# directories containing `*' or `\' aren't allowed on Cygwin/Windows
if {! [is_cygwin]} {
Expand All @@ -33,8 +38,8 @@ proc teardown {} {
assert_bash_exec {(cd $TESTDIR/tmp && rm -- a\*b/j && rmdir a\*b/ || true)}
}
assert_bash_exec {unset COMPREPLY cur}
assert_bash_exec {unset -f _f _g}
assert_bash_exec {complete -r f g}
assert_bash_exec {unset -f _f _g _fd}
assert_bash_exec {complete -r f g fd}
assert_env_unmodified {
/OLDPWD/d
/OLD_CTYPE/d
Expand Down Expand Up @@ -260,4 +265,12 @@ if {
sync_after_int


set test "completing fd a\\ should return a\\ b/"
set cmd "fd a\\ "
assert_complete_dir "a\\ b/" $cmd "$::srcdir/fixtures/_filedir" $test -nospace


sync_after_int


teardown

0 comments on commit d2920b7

Please sign in to comment.