Fix expanding quoted tilde in _known_hosts_real.
- Added unit test "Files starting with tilde (~) should work" to unit/_known_hosts_real.exp
This commit is contained in:
parent
511b7c7f35
commit
a07b5c5ffd
@ -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
|
||||
|
4
test/fixtures/_known_hosts_real/config_tilde
vendored
Normal file
4
test/fixtures/_known_hosts_real/config_tilde
vendored
Normal file
@ -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
|
1
test/fixtures/_known_hosts_real/known_hosts3
vendored
Normal file
1
test/fixtures/_known_hosts_real/known_hosts3
vendored
Normal file
@ -0,0 +1 @@
|
||||
three
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user