ssh kitten: Fix a regression causing hostname directives in ssh.conf not matching when username is specified

This commit is contained in:
Kovid Goyal 2023-09-08 15:10:46 +05:30
parent d1d888ce19
commit af4213579c
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 2 deletions

View file

@ -76,6 +76,8 @@ Detailed list of changes
- Config file format: allow splitting lines by starting subsequent lines with a backslash (:pull:`6603`)
- ssh kitten: Fix a regression causing hostname directives in :file:`ssh.conf` not matching when username is specified (:disc:`6609`)
0.29.2 [2023-07-27]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -49,19 +49,23 @@ func get_destination(hostname string) (username, hostname_for_match string) {
username = u.Username
}
hostname_for_match = hostname
parsed := false
if strings.HasPrefix(hostname, "ssh://") {
p, err := url.Parse(hostname)
if err == nil {
hostname_for_match = p.Hostname()
parsed = true
if p.User.Username() != "" {
username = p.User.Username()
}
}
} else if strings.Contains(hostname, "@") && hostname[0] != '@' {
username, hostname_for_match, _ = strings.Cut(hostname, "@")
parsed = true
}
if strings.Contains(hostname, "@") && hostname[0] != '@' {
_, hostname_for_match, _ = strings.Cut(hostname_for_match, "@")
if !parsed && strings.Contains(hostname, "@") && hostname[0] != '@' {
_, hostname_for_match, _ = strings.Cut(hostname, "@")
parsed = true
}
hostname_for_match, _, _ = strings.Cut(hostname_for_match, ":")
return