diff options
-rw-r--r-- | contrib/mount | 13 | ||||
-rw-r--r-- | test/lib/completions/mount.exp | 17 |
2 files changed, 28 insertions, 2 deletions
diff --git a/contrib/mount b/contrib/mount index 1896dded..e4a74372 100644 --- a/contrib/mount +++ b/contrib/mount @@ -34,6 +34,13 @@ _reply_compgen_array() IFS=$oldifs } +# Unescape strings in the linux fstab(5) format (with octal escapes). +__linux_fstab_unescape() { + eval $1="'${!1//\'/\047}'" + eval $1="'${!1/%\\/\\\\}'" + eval "$1=$'${!1}'" +} + # Complete linux fstab entries. # # Reads a file from stdin in the linux fstab(5) format; as used by /etc/fstab @@ -45,11 +52,13 @@ _linux_fstab() # Read and unescape values into COMPREPLY local fs_spec fs_file fs_other while read -r fs_spec fs_file fs_other; do + __linux_fstab_unescape fs_spec + __linux_fstab_unescape fs_file if [[ $fs_spec = [#]* ]]; then continue; fi local oldifs="$IFS" IFS=$'\0' - [[ $fs_spec = */* ]] && eval "COMPREPLY+=( $'${fs_spec//\'/\047}' )"; - [[ $fs_file = */* ]] && eval "COMPREPLY+=( $'${fs_file//\'/\047}' )"; + [[ $fs_spec = */* ]] && COMPREPLY+=("$fs_spec"); + [[ $fs_file = */* ]] && COMPREPLY+=("$fs_file"); IFS="$oldifs" done diff --git a/test/lib/completions/mount.exp b/test/lib/completions/mount.exp index 869452b0..4473c70f 100644 --- a/test/lib/completions/mount.exp +++ b/test/lib/completions/mount.exp @@ -57,6 +57,23 @@ assert_bash_exec {PATH="$OLDPATH"; unset -v OLDPATH} sync_after_int +set test "Testing internal __linux_fstab_unescape function for mount" +# One round of slashes is for bash. +assert_bash_exec {var=one\'two\\040three\\} +assert_bash_exec {__linux_fstab_unescape var} +set cmd {echo $var} +send "$cmd\r" +expect { + -ex "$cmd\r\none'two three\\" { pass $test } +# default { fail $test } +} +assert_bash_exec {unset var} + + +sync_after_int + + +# Begin testing through mnt (see setup_dummy_mnt). assert_complete {/mnt/nice-test-path} {mnt /mnt/nice-test-p} sync_after_int |