Skip to content

Commit a7cb149

Browse files
committed
fix: Improve regexes
1 parent 9d64680 commit a7cb149

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cli/configssh.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ const (
4949
var (
5050
// Find the first Host and Match statement as these restrict the
5151
// following declarations to be used conditionally.
52-
sshHostRe = regexp.MustCompile(`(?m)^\s*((?i)Host|Match)\s.*$`)
53-
// Find the semantically correct include statement.
54-
sshCoderIncludedRe = regexp.MustCompile(`(?m)^\s*((?i)Include) coder(\s.*)?$`)
52+
sshHostRe = regexp.MustCompile(`(?m)^[\t ]*((?i)Host|Match)\s[^\n\r]*$`)
53+
// Find the semantically correct include statement. Since the user can
54+
// modify their configuration as they see fit, there could be:
55+
// - Leading indentation (space, tab)
56+
// - Trailing indentation (space, tab), followed by e.g. a comment or
57+
// another file to Include (we don't want to support this, but
58+
// explicitly blocking it adds complexity)
59+
// - Select newline after Include statement for removal purposes
60+
sshCoderIncludedRe = regexp.MustCompile(`(?m)^[\t ]*((?i)Include) coder([\t ].*)?[\r]?[\n]?$`)
5561
)
5662

5763
// sshCoderConfigOptions represents options that can be stored and read

0 commit comments

Comments
 (0)