Skip to content

Commit

Permalink
wezterm-ssh: add support for comments in Match statements
Browse files Browse the repository at this point in the history
Looking at the openssh-portable code, it seems that inline comments are
only handled specially on `Match` and `ProxyJump` statements. This
change adds inline comment handling.

Closes: #5498
See-also: https://github.com/openssh/openssh-portable/blob/ee6b9e661633fcefd29dba0c811cecbc4d027f6f/readconf.c#L652
Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Jul 3, 2024
1 parent 69686f4 commit 949d503
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions wezterm-ssh/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ impl ParsedConfigFile {
if line.is_empty() || line.starts_with('#') {
continue;
}
// Only `Match` and `ProxyJump` options seem to allow inline comments.
// The latter is not handled.

if let Some(sep) = line.find(|c: char| c == '=' || c.is_whitespace()) {
let (k, v) = line.split_at(sep);
Expand Down Expand Up @@ -293,7 +295,14 @@ impl ParsedConfigFile {
let mut criteria = vec![];
let mut context = Context::FirstPass;

let mut tokens = v.split_ascii_whitespace();
let mut tokens = v.split_ascii_whitespace().map_while(|tok| {
// This is for compatability, see `match_cfg_line` in openssh's `readconf.c`.
if tok.starts_with("#") {
None
} else {
Some(tok)
}
});

while let Some(cname) = tokens.next() {
match cname.to_lowercase().as_str() {
Expand Down Expand Up @@ -1080,7 +1089,7 @@ Config {
Something first
# the prior Something takes precedence
Something ignored
Match Host 192.168.1.8,wopr
Match Host 192.168.1.8,wopr # fun games
FowardAgent yes
IdentityFile "%d/.ssh/id_pub.dsa"
Expand Down

0 comments on commit 949d503

Please sign in to comment.