_filedir: Properly quote paths to avoid unexpected expansion.
This commit is contained in:
parent
d7a6fb1f47
commit
98f90ebdf8
@ -562,33 +562,32 @@ _filedir()
|
|||||||
_tilde "$cur" || return 0
|
_tilde "$cur" || return 0
|
||||||
|
|
||||||
local -a toks
|
local -a toks
|
||||||
local quoted tmp
|
local quoted x tmp
|
||||||
|
|
||||||
_quote_readline_by_ref "$cur" quoted
|
_quote_readline_by_ref "$cur" quoted
|
||||||
toks=( $(
|
x=$( compgen -d -- "$quoted" ) &&
|
||||||
compgen -d -- "$quoted" | {
|
while read -r tmp; do
|
||||||
while read -r tmp; do
|
toks+=( "$tmp" )
|
||||||
# TODO: I have removed a "[ -n $tmp ] &&" before 'printf ..',
|
done <<< "$x"
|
||||||
# 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
|
|
||||||
}
|
|
||||||
))
|
|
||||||
|
|
||||||
if [[ "$1" != -d ]]; then
|
if [[ "$1" != -d ]]; then
|
||||||
# Munge xspec to contain uppercase version too
|
# Munge xspec to contain uppercase version too
|
||||||
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
|
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
|
||||||
xspec=${1:+"!*.@($1|${1^^})"}
|
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
|
fi
|
||||||
|
|
||||||
# If the filter failed to produce anything, try without it if configured to
|
# If the filter failed to produce anything, try without it if configured to
|
||||||
[[ -n ${COMP_FILEDIR_FALLBACK:-} && \
|
[[ -n ${COMP_FILEDIR_FALLBACK:-} && \
|
||||||
-n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
|
-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
|
if [[ ${#toks[@]} -ne 0 ]]; then
|
||||||
# 2>/dev/null for direct invocation, e.g. in the _filedir unit test
|
# 2>/dev/null for direct invocation, e.g. in the _filedir unit test
|
||||||
@ -1806,7 +1805,6 @@ _filedir_xspec()
|
|||||||
toks=( $(
|
toks=( $(
|
||||||
compgen -d -- "$(quote_readline "$cur")" | {
|
compgen -d -- "$(quote_readline "$cur")" | {
|
||||||
while read -r tmp; do
|
while read -r tmp; do
|
||||||
# see long TODO comment in _filedir() --David
|
|
||||||
printf '%s\n' $tmp
|
printf '%s\n' $tmp
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
1
test/fixtures/_filedir/brackets/[x]
vendored
Normal file
1
test/fixtures/_filedir/brackets/[x]
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
test/fixtures/_filedir/brackets/x
vendored
Normal file
1
test/fixtures/_filedir/brackets/x
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
@ -226,6 +226,12 @@ foreach name {f f2} {
|
|||||||
sync_after_int
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
|
set cmd "$name \\\[x"
|
||||||
|
assert_complete_dir {\[x\]} $cmd "$::srcdir/fixtures/_filedir/brackets"
|
||||||
|
|
||||||
|
|
||||||
|
sync_after_int
|
||||||
|
|
||||||
}; # foreach
|
}; # foreach
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user