diff --git a/server/handlers/sshd_config/analyzer/match.go b/server/handlers/sshd_config/analyzer/match.go index fee46ee..4989a07 100644 --- a/server/handlers/sshd_config/analyzer/match.go +++ b/server/handlers/sshd_config/analyzer/match.go @@ -12,10 +12,12 @@ import ( protocol "github.com/tliron/glsp/protocol_3_16" ) +var matchOption = fields.CreateNormalizedName("Match") + func analyzeMatchBlocks( ctx *analyzerContext, ) { - for matchBlock, options := range ctx.document.Indexes.AllOptionsPerName["Match"] { + for matchBlock, options := range ctx.document.Indexes.AllOptionsPerName[matchOption] { option := options[0] // Check if the match block has filled out all fields if matchBlock == nil || matchBlock.MatchValue == nil || len(matchBlock.MatchValue.Entries) == 0 { diff --git a/server/handlers/sshd_config/ast/parser_test.go b/server/handlers/sshd_config/ast/parser_test.go index 28081ff..a47bae1 100644 --- a/server/handlers/sshd_config/ast/parser_test.go +++ b/server/handlers/sshd_config/ast/parser_test.go @@ -234,7 +234,7 @@ Match Address 192.168.0.2 } firstOption, firstMatchBlock := p.FindOption(uint32(3)) - if !(firstOption.Key.Key == "PasswordAuthentication" && firstOption.OptionValue.Value.Value == "yes") { + if !(firstOption.Key.Key == "passwordauthentication" && firstOption.OptionValue.Value.Value == "yes") { t.Errorf("Expected first option to be 'PasswordAuthentication yes' and first match block to be 'Match Address 192.168.0.1', but got: %v, %v", firstOption, firstMatchBlock) } diff --git a/server/handlers/sshd_config/indexes/indexes_handlers.go b/server/handlers/sshd_config/indexes/indexes_handlers.go index 97069c1..5c90047 100644 --- a/server/handlers/sshd_config/indexes/indexes_handlers.go +++ b/server/handlers/sshd_config/indexes/indexes_handlers.go @@ -11,6 +11,8 @@ import ( var whitespacePattern = regexp.MustCompile(`\S+`) +var includeOption = fields.CreateNormalizedName("Include") + func CreateIndexes(config ast.SSHDConfig) (*SSHDIndexes, []common.LSPError) { errs := make([]common.LSPError, 0) indexes := &SSHDIndexes{ @@ -42,7 +44,7 @@ func CreateIndexes(config ast.SSHDConfig) (*SSHDIndexes, []common.LSPError) { } // Add Includes - for matchBlock, options := range indexes.AllOptionsPerName["Include"] { + for matchBlock, options := range indexes.AllOptionsPerName[includeOption] { includeOption := options[0] rawValue := includeOption.OptionValue.Value.Value pathIndexes := whitespacePattern.FindAllStringIndex(rawValue, -1) diff --git a/server/handlers/sshd_config/indexes/indexes_test.go b/server/handlers/sshd_config/indexes/indexes_test.go index 25a772d..43753bb 100644 --- a/server/handlers/sshd_config/indexes/indexes_test.go +++ b/server/handlers/sshd_config/indexes/indexes_test.go @@ -34,7 +34,7 @@ Match Address 192.168.0.1/24 } firstMatchBlock := config.FindMatchBlock(uint32(6)) - opts := indexes.AllOptionsPerName["PermitRootLogin"] + opts := indexes.AllOptionsPerName["permitrootlogin"] if !(len(opts) == 2 && len(opts[nil]) == 1 && opts[nil][0].Value.Value == "PermitRootLogin yes" && @@ -42,7 +42,7 @@ Match Address 192.168.0.1/24 len(opts[firstMatchBlock]) == 1 && opts[firstMatchBlock][0].Value.Value == "\tPermitRootLogin no" && opts[firstMatchBlock][0].Start.Line == 6 && - opts[firstMatchBlock][0].Key.Key == "PermitRootLogin") { + opts[firstMatchBlock][0].Key.Key == "permitrootlogin") { t.Errorf("Expected 3 PermitRootLogin options, but got %v", opts) } }