(mount) Make mount work properly with ' in fstab

This commit is contained in:
Crestez Dan Leonard 2010-02-08 09:50:39 +02:00
parent c0b77a03f5
commit 2f61acd068
3 changed files with 15 additions and 6 deletions

View File

@ -19,13 +19,14 @@ _reply_compgen_array()
# argument. # argument.
local i wlist local i wlist
for i in ${!COMPREPLY[*]}; do for i in ${!COMPREPLY[*]}; do
local q=`printf %q "${COMPREPLY[$i]}"` local q=$(quote "$(printf %q "${COMPREPLY[$i]}")")
wlist+=$(quote "$q")$'\n' wlist+=$q$'\n'
done done
# We also have to add another round of escaping to $cur. # We also have to add another round of escaping to $cur.
local ecur="$cur" local ecur="$cur"
ecur="${ecur//\\/\\\\}" ecur="${ecur//\\/\\\\}"
ecur="${ecur//\'/\'}"
# Actually generate completions. # Actually generate completions.
local oldifs=$IFS local oldifs=$IFS
@ -47,8 +48,8 @@ _linux_fstab()
if [[ $fs_spec = [#]* ]]; then continue; fi if [[ $fs_spec = [#]* ]]; then continue; fi
local oldifs="$IFS" local oldifs="$IFS"
IFS=$'\0' IFS=$'\0'
[[ $fs_spec = */* ]] && eval "COMPREPLY+=( $'$fs_spec' )"; [[ $fs_spec = */* ]] && eval "COMPREPLY+=( $'${fs_spec//\'/\047}' )";
[[ $fs_file = */* ]] && eval "COMPREPLY+=( $'$fs_file' )"; [[ $fs_file = */* ]] && eval "COMPREPLY+=( $'${fs_file//\'/\047}' )";
IFS="$oldifs" IFS="$oldifs"
done done

View File

@ -14,9 +14,11 @@ none /debug debugfs defaults,noauto 0 0
# Contains '\n' and '\ ' # Contains '\n' and '\ '
/mnt/nice\012test\040path /dev/null auto ro,noauto 0 0 /mnt/nice\012test\040path /dev/null auto ro,noauto 0 0
# Test apostrophe
/mnt/nice'test-path /dev/null auto ro,noauto 0 0
/mnt/other'test\040path /dev/null auto ro,noauto 0 0
# Test some labels # Test some labels
LABEL=Ubuntu\040Karmic /mnt/ubuntu auto no,noauto 0 0 LABEL=Ubuntu\040Karmic /mnt/ubuntu auto no,noauto 0 0
LABEL=Fedora /mnt/fedora auto ro,noauto 0 0 LABEL=Fedora /mnt/fedora auto ro,noauto 0 0
LABEL=Debian-it's\040awesome /mnt/debian auto ro,noauto 0 0 LABEL=Debian-it's\040awesome /mnt/debian auto ro,noauto 0 0
#/dev/null /mnt/nice'testxxxpath auto ro,noauto 0 0

View File

@ -76,6 +76,12 @@ sync_after_int
assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$} assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$}
sync_after_int sync_after_int
assert_complete {/mnt/nice\'test-path} {mnt /mnt/nice\'}
sync_after_int
assert_complete {/mnt/other\'test\ path} {mnt /mnt/other}
sync_after_int
# This does not work. Proper support for this requires smarter parsing of # This does not work. Proper support for this requires smarter parsing of
# $COMP_LINE and it's not worth doing just for mount. # $COMP_LINE and it's not worth doing just for mount.
#assert_complete {$'/mnt/nice\ntest-path'} {mnt $'/mnt/nice\n} #assert_complete {$'/mnt/nice\ntest-path'} {mnt $'/mnt/nice\n}