-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix regex expression in SSH config parser #28
Conversation
config.go
Outdated
@@ -37,7 +37,7 @@ func ParseSSHConfigFile(path string) (map[string]SSHClientOptions, error) { | |||
|
|||
// Read lines in reverse order and parse option for each Host section: | |||
lines := strings.Split(string(content), "\n") | |||
hostExpr := regexp.MustCompile("\\s*Host\\s*=?\\s*(.+)") | |||
hostExpr := regexp.MustCompile("\\s*Host\\s*(=?)\\s*(.+)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's possible to just update this regexp as "^\\s*Host\\b\\s*=?\\s*(.+)"
and we're done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, that worked great. I pushed the changes. Thanks!
config.go
Outdated
@@ -37,7 +37,7 @@ func ParseSSHConfigFile(path string) (map[string]SSHClientOptions, error) { | |||
|
|||
// Read lines in reverse order and parse option for each Host section: | |||
lines := strings.Split(string(content), "\n") | |||
hostExpr := regexp.MustCompile("\\s*Host\\s*=?\\s*(.+)") | |||
hostExpr := regexp.MustCompile("\\s*Host\\b\\s*=?\\s*(.+)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It think it's better to add the leading ^
to the regexp and so it's exact match of Host
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this?
^Host\\b\\s*=?\\s*(.+)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one mentioned on #28 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks!
Thanks @jeloou . |
I've the following config in my
~/.ssh/config
:but this isn't parsed correctly by
ParseSSHConfigFile
because the first host hasStrictHostKeyChecking
config.this fix handles that scenario correctly.