[Bash-completion-commits] [SCM] bash-completion branch, master, updated. a07b5c5ffd9fda19ed8d990776d9b1dac6a5bbdc

Freddy Vulto fvulto at gmail.com
Sun Nov 29 13:43:44 UTC 2009


The following commit has been merged in the master branch:
commit a07b5c5ffd9fda19ed8d990776d9b1dac6a5bbdc
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Sun Nov 29 14:42:42 2009 +0100

    Fix expanding quoted tilde in _known_hosts_real.
    - Added unit test "Files starting with tilde (~) should work" to
      unit/_known_hosts_real.exp

diff --git a/bash_completion b/bash_completion
index 05f5c91..a29138c 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1266,7 +1266,10 @@ _known_hosts_real()
         #          breakage! Alioth#311595)
         tmpkh=( $( sed -ne 's/^[ \t]*\([Gg][Ll][Oo][Bb][Aa][Ll]\|[Uu][Ss][Ee][Rr]\)[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\2/p' "${config[@]}" | sort -u ) )
         for i in "${tmpkh[@]}"; do
-            i=$( eval echo "$i" ) # expand ~
+            # Remove possible quotes
+            i=${i//\"}
+            # Eval/expand `~' or `~user', only if first char is tilde (~)
+            [ "${i:0:1}" = "~" ] && i=$( eval echo "$i" )
             [ -r "$i" ] && kh=( "${kh[@]}" "$i" )
         done
         IFS=$OIFS
diff --git a/test/fixtures/_known_hosts_real/config_tilde b/test/fixtures/_known_hosts_real/config_tilde
new file mode 100644
index 0000000..1068e29
--- /dev/null
+++ b/test/fixtures/_known_hosts_real/config_tilde
@@ -0,0 +1,4 @@
+# With quotes and tilde
+UserKnownHostsFile "~/fixtures/_known_hosts_real/known_hosts2"
+# Without quotes, with tilde
+UserKnownHostsFile ~/fixtures/_known_hosts_real/known_hosts3
diff --git a/test/fixtures/_known_hosts_real/known_hosts3 b/test/fixtures/_known_hosts_real/known_hosts3
new file mode 100644
index 0000000..2bdf67a
--- /dev/null
+++ b/test/fixtures/_known_hosts_real/known_hosts3
@@ -0,0 +1 @@
+three
diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp
index c6d8a8a..0cdf63c 100644
--- a/test/unit/_known_hosts_real.exp
+++ b/test/unit/_known_hosts_real.exp
@@ -4,7 +4,10 @@ proc setup {} {
 
 
 proc teardown {} {
-    assert_env_unmodified {/COMPREPLY=/d}
+    assert_env_unmodified {
+        /COMPREPLY=/d
+        /OLDHOME=/d
+    }
 }; # teardown()
 
 
@@ -59,8 +62,8 @@ send "$cmd\r"
 expect -ex "$cmd\r\n"
 expect {
     -re "^$hosts\r\n/@$"  { pass "$test" }
-    -re "^$hosts_orig\r\n/@$"  { xfail "$test (config file)" }
-    -re "^$hosts_config\r\n/@$"  { xfail "$test (known hosts file)" }
+    -re "^$hosts_orig\r\n/@$"  { fail "$test (config file)" }
+    -re "^$hosts_config\r\n/@$"  { fail "$test (known hosts file)" }
     -re /@ { unresolved "$test at prompt" }
     default { unresolved "$test" }
 }; # expect
@@ -69,6 +72,33 @@ expect {
 sync_after_int
 
 
+set test "Files starting with tilde (~) should work"
+set hosts [get_hosts]
+    # Host `two' is defined in ./fixtures/_known_hosts_real/known_hosts2
+    # Host `three' is defined in ./fixtures/_known_hosts_real/known_hosts3
+lappend hosts two three
+set hosts [join [lsort -ascii $hosts] "\\s+"]
+    # Setup environment
+set cmd {OLDHOME=$HOME; HOME=$TESTDIR}
+send "$cmd\r"
+expect -ex "$cmd\r\n/@"
+    # Call _known_hosts
+set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config_tilde ''; echo_array COMPREPLY}
+send "$cmd\r"
+expect -ex "$cmd\r\n"
+expect {
+    -re "^$hosts\r\n/@$"  { pass "$test" }
+    default { unresolved "$test" }
+}; # expect
+    # Teardown environment
+set cmd {HOME=$OLDHOME}
+send "$cmd\r"
+expect -ex "$cmd\r\n/@"
+
+
+sync_after_int
+
+
 set test "Empty COMP_KNOWN_HOSTS_WITH_HOSTFILE should omit HOSTFILE"
 assert_bash_exec "COMP_KNOWN_HOSTS_WITH_HOSTFILE="
 set hosts [get_hosts_avahi]

-- 
bash-completion



More information about the Bash-completion-commits mailing list