summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murzov <e-mail@date.by>2012-01-20 04:58:37 +0400
committerIgor Murzov <e-mail@date.by>2012-01-20 05:11:17 +0400
commit98f90ebdf8b7ccf49e7854640712af1ff4a47871 (patch)
treea295afe686ab844d9511f4d4e926577646079e54
parentd7a6fb1f47d5daafb555f09fb5d9bd544ae99ec6 (diff)
downloadbash-completion-98f90ebdf8b7ccf49e7854640712af1ff4a47871.tar.gz
_filedir: Properly quote paths to avoid unexpected expansion.
-rw-r--r--bash_completion30
-rw-r--r--test/fixtures/_filedir/brackets/[x]1
-rw-r--r--test/fixtures/_filedir/brackets/x1
-rw-r--r--test/unit/_filedir.exp6
4 files changed, 22 insertions, 16 deletions
diff --git a/bash_completion b/bash_completion
index b9585ac8..a080b1c8 100644
--- a/bash_completion
+++ b/bash_completion
@@ -562,33 +562,32 @@ _filedir()
_tilde "$cur" || return 0
local -a toks
- local quoted tmp
+ local quoted x tmp
_quote_readline_by_ref "$cur" quoted
- toks=( $(
- compgen -d -- "$quoted" | {
- while read -r tmp; do
- # TODO: I have removed a "[ -n $tmp ] &&" before 'printf ..',
- # and everything works again. If this bug suddenly
- # appears again (i.e. "cd /b<TAB>" becomes "cd /"),
- # remember to check for other similar conditionals (here
- # and _filedir_xspec()). --David
- printf '%s\n' $tmp
- done
- }
- ))
+ x=$( compgen -d -- "$quoted" ) &&
+ while read -r tmp; do
+ toks+=( "$tmp" )
+ done <<< "$x"
if [[ "$1" != -d ]]; then
# Munge xspec to contain uppercase version too
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
xspec=${1:+"!*.@($1|${1^^})"}
- toks+=( $( compgen -f -X "$xspec" -- $quoted ) )
+ x=$( compgen -f -X "$xspec" -- $quoted ) &&
+ while read -r tmp; do
+ toks+=( "$tmp" )
+ done <<< "$x"
fi
# If the filter failed to produce anything, try without it if configured to
[[ -n ${COMP_FILEDIR_FALLBACK:-} && \
-n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
- toks+=( $( compgen -f -- $quoted ) )
+ x=$( compgen -f -- $quoted ) &&
+ while read -r tmp; do
+ toks+=( "$tmp" )
+ done <<< "$x"
+
if [[ ${#toks[@]} -ne 0 ]]; then
# 2>/dev/null for direct invocation, e.g. in the _filedir unit test
@@ -1806,7 +1805,6 @@ _filedir_xspec()
toks=( $(
compgen -d -- "$(quote_readline "$cur")" | {
while read -r tmp; do
- # see long TODO comment in _filedir() --David
printf '%s\n' $tmp
done
}
diff --git a/test/fixtures/_filedir/brackets/[x] b/test/fixtures/_filedir/brackets/[x]
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/fixtures/_filedir/brackets/[x]
@@ -0,0 +1 @@
+
diff --git a/test/fixtures/_filedir/brackets/x b/test/fixtures/_filedir/brackets/x
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/fixtures/_filedir/brackets/x
@@ -0,0 +1 @@
+
diff --git a/test/unit/_filedir.exp b/test/unit/_filedir.exp
index 0bba8314..b8cc2009 100644
--- a/test/unit/_filedir.exp
+++ b/test/unit/_filedir.exp
@@ -226,6 +226,12 @@ foreach name {f f2} {
sync_after_int
+ set cmd "$name \\\[x"
+ assert_complete_dir {\[x\]} $cmd "$::srcdir/fixtures/_filedir/brackets"
+
+
+ sync_after_int
+
}; # foreach