Skip to content
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

Merged
merged 3 commits into from
Dec 12, 2017

Conversation

jeloou
Copy link
Contributor

@jeloou jeloou commented Dec 1, 2017

I've the following config in my ~/.ssh/config:

Host sshd.docker0
  ForwardAgent yes
  StrictHostKeyChecking no
  Port 32770
  User joseph

Host sshd.docker1
  Port 32771
  User joseph

but this isn't parsed correctly by ParseSSHConfigFile because the first host has StrictHostKeyChecking config.

this fix handles that scenario correctly.

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*(.+)")
Copy link
Collaborator

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.

See https://play.golang.org/p/J8GdA1UOTv

Copy link
Contributor Author

@jeloou jeloou Dec 8, 2017

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*(.+)")
Copy link
Collaborator

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.

Copy link
Contributor Author

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*(.+)

Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks!

@mrkschan mrkschan merged commit 48fdbdf into crosbymichael:master Dec 12, 2017
@mrkschan
Copy link
Collaborator

Thanks @jeloou .

mattn pushed a commit to mattn/slex that referenced this pull request Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants