Skip to content

Commit a136272

Browse files
committed
Make known_hosts hostname matching more lenient
Documentation for the known_hosts file format specifies "Hostnames is a comma-separated list of patterns [...]". The regexps we had is unnecessariliy strict, allowing only a subset of valid sequences. Make it more lenient (and simple) to match more valid ones.
1 parent d560a08 commit a136272

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

ssh-config-mode.el

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@ We permit underscores.")
301301
ssh-known-hosts-regex-hostname
302302
"\\)"))
303303

304+
(defvar ssh-known-hosts-regex-hostname-pattern
305+
(concat
306+
"\\(?:"
307+
ssh-known-hosts-regex-hostname
308+
"\\|"
309+
ssh-known-hosts-regex-ip
310+
"\\|"
311+
;; [host-or-ip]:222
312+
"\\(?:\\[" ssh-known-hosts-regex-host "\\]:" ssh-known-hosts-regex-port "\\)"
313+
"\\)"))
314+
304315
;; NOTE: font-lock-studio might be of help when making changes.
305316
(defvar ssh-known-hosts-font-lock-keywords
306317
;; We want to match lines like the following:
@@ -320,27 +331,11 @@ We permit underscores.")
320331
ssh-known-hosts-regex-hashed
321332
"\\|"
322333

323-
;; hostname-only
324-
ssh-known-hosts-regex-hostname
325-
"\\|"
326-
327-
;; ip-only
328-
ssh-known-hosts-regex-ip
329-
"\\|"
330-
331-
;; hostname "," ip
332-
"\\(?:" ssh-known-hosts-regex-hostname "," ssh-known-hosts-regex-ip "\\)"
333-
"\\|"
334-
335-
;; [host-or-ip]:222
336-
"\\(?:\\[" ssh-known-hosts-regex-host "\\]:" ssh-known-hosts-regex-port "\\)"
337-
"\\|"
338-
339-
;; We arent matching ports, but they should be the same.
340-
;; [ssh.github.com]:443,[192.1.2.3]:443
341-
"\\(?:"
342-
"\\[" ssh-known-hosts-regex-hostname "\\]:" ssh-known-hosts-regex-port ","
343-
"\\[" ssh-known-hosts-regex-ip "\\]:" ssh-known-hosts-regex-port "\\)"
334+
;; list of comma separated hostname patterns
335+
ssh-known-hosts-regex-hostname-pattern
336+
"\\(?:,"
337+
ssh-known-hosts-regex-hostname-pattern
338+
"\\)*"
344339

345340
"\\)"
346341
"[ \t]+"

0 commit comments

Comments
 (0)