[bash,zsh] Do not end the hostname analysis on "]" in ~/.ssh/known_hosts

An entry of the form `[example.com]:port,192.168.0.1 ...` in
~/.ssh/known_hosts are not properly processed.  The current
implementation gives up the matching on the first occurrence of `]`,
the subsequent 192.168.0.1 would not be extracted.  This patch
continues the analysis and removes "]" together with "[".

This patch also removes the ":port" part from the hostnames in
~/.ssh/known_hosts.  One cannot use the form "hostname:port" in the
arguments to the ssh command anyway.
This commit is contained in:
Koichi Murase
2025-06-03 21:30:56 +09:00
committed by Junegunn Choi
parent b5cd8880b1
commit 585cfaef8b
2 changed files with 4 additions and 4 deletions

View File

@@ -503,9 +503,9 @@ if ! declare -F __fzf_list_hosts > /dev/null; then
) \
<(
__fzf_exec_awk -F ',' '
match($0, /^[[a-zA-Z0-9.,:-]+/) {
match($0, /^[][a-zA-Z0-9.,:-]+/) {
$0 = substr($0, 1, RLENGTH)
gsub(/\[/, "")
gsub(/[][]|:[^,]*/, "")
for (i = 1; i <= NF; i++)
print $i
}

View File

@@ -281,9 +281,9 @@ if ! declare -f __fzf_list_hosts > /dev/null; then
) \
<(
__fzf_exec_awk -F ',' '
match($0, /^[[a-zA-Z0-9.,:-]+/) {
match($0, /^[][a-zA-Z0-9.,:-]+/) {
$0 = substr($0, 1, RLENGTH)
gsub(/\[/, "")
gsub(/[][]|:[^,]*/, "")
for (i = 1; i <= NF; i++)
print $i
}